Problems with Unified Logging, StaticString, CustomStringConvertible and description [duplicate]
This question already has an answer here:
Using os_log to log function arguments, or other dynamic data
1 answer
I'm wondering how I'm supposed to handle the following fairly common scenario using Unified Logging. Let's say I have an object of class Foo which I want to log. Foo implements the CustomStringConvertible protocol, so I can get a description of the object I can use in my logs:
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
let myFoo = Foo()
If I call print(myFoo)
, I get a nice description of Foo. However, os_log(myFoo)
won't work since description is not a StaticString. Is there a way to accomplish what I'm trying to do?
swift
marked as duplicate by Martin R
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 5:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Using os_log to log function arguments, or other dynamic data
1 answer
I'm wondering how I'm supposed to handle the following fairly common scenario using Unified Logging. Let's say I have an object of class Foo which I want to log. Foo implements the CustomStringConvertible protocol, so I can get a description of the object I can use in my logs:
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
let myFoo = Foo()
If I call print(myFoo)
, I get a nice description of Foo. However, os_log(myFoo)
won't work since description is not a StaticString. Is there a way to accomplish what I'm trying to do?
swift
marked as duplicate by Martin R
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 5:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Using os_log to log function arguments, or other dynamic data
1 answer
I'm wondering how I'm supposed to handle the following fairly common scenario using Unified Logging. Let's say I have an object of class Foo which I want to log. Foo implements the CustomStringConvertible protocol, so I can get a description of the object I can use in my logs:
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
let myFoo = Foo()
If I call print(myFoo)
, I get a nice description of Foo. However, os_log(myFoo)
won't work since description is not a StaticString. Is there a way to accomplish what I'm trying to do?
swift
This question already has an answer here:
Using os_log to log function arguments, or other dynamic data
1 answer
I'm wondering how I'm supposed to handle the following fairly common scenario using Unified Logging. Let's say I have an object of class Foo which I want to log. Foo implements the CustomStringConvertible protocol, so I can get a description of the object I can use in my logs:
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
let myFoo = Foo()
If I call print(myFoo)
, I get a nice description of Foo. However, os_log(myFoo)
won't work since description is not a StaticString. Is there a way to accomplish what I'm trying to do?
This question already has an answer here:
Using os_log to log function arguments, or other dynamic data
1 answer
swift
swift
edited Nov 20 at 23:45
asked Nov 20 at 23:14
pondermatic
3,52183851
3,52183851
marked as duplicate by Martin R
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 5:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Martin R
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 5:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I'm having trouble understanding what part you find difficult, so here's a complete example and you can pick out of it whatever you need:
import UIKit
import os
let mylog = OSLog(subsystem: "com.neuburg.matt", category: "testing")
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let foo = Foo()
os_log("%{public}@", log: mylog, String(describing:foo))
}
}
Prints:
[testing] <Foo: bar = 1>
...which I believe was the goal, no?
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm having trouble understanding what part you find difficult, so here's a complete example and you can pick out of it whatever you need:
import UIKit
import os
let mylog = OSLog(subsystem: "com.neuburg.matt", category: "testing")
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let foo = Foo()
os_log("%{public}@", log: mylog, String(describing:foo))
}
}
Prints:
[testing] <Foo: bar = 1>
...which I believe was the goal, no?
add a comment |
I'm having trouble understanding what part you find difficult, so here's a complete example and you can pick out of it whatever you need:
import UIKit
import os
let mylog = OSLog(subsystem: "com.neuburg.matt", category: "testing")
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let foo = Foo()
os_log("%{public}@", log: mylog, String(describing:foo))
}
}
Prints:
[testing] <Foo: bar = 1>
...which I believe was the goal, no?
add a comment |
I'm having trouble understanding what part you find difficult, so here's a complete example and you can pick out of it whatever you need:
import UIKit
import os
let mylog = OSLog(subsystem: "com.neuburg.matt", category: "testing")
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let foo = Foo()
os_log("%{public}@", log: mylog, String(describing:foo))
}
}
Prints:
[testing] <Foo: bar = 1>
...which I believe was the goal, no?
I'm having trouble understanding what part you find difficult, so here's a complete example and you can pick out of it whatever you need:
import UIKit
import os
let mylog = OSLog(subsystem: "com.neuburg.matt", category: "testing")
class Foo: CustomStringConvertible {
var bar:Int = 1
var description: String {
return "<(type(of: self)): bar = (bar)>"
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let foo = Foo()
os_log("%{public}@", log: mylog, String(describing:foo))
}
}
Prints:
[testing] <Foo: bar = 1>
...which I believe was the goal, no?
answered Nov 21 at 0:03
matt
323k45519720
323k45519720
add a comment |
add a comment |