You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added some color to easily help me debug issues in my code when printing to the console.
Would there be any support for something like this? I basically modified the StreamLogHandler to add an icon before logging to the console.
Here's the rough change inside the public func log.
`public func log(level: Logger.Level,
message: Logger.Message,
metadata: Logger.Metadata?,
source: String,
file: String,
function: String,
line: UInt) {
let prettyMetadata = metadata?.isEmpty ?? true
? self.prettyMetadata
: self.prettify(self.metadata.merging(metadata!, uniquingKeysWith: { _, new in new }))
let icon:String
switch level {
case .trace:
icon = "📣"
case .debug:
icon = "🐛"
case .info:
icon = "ℹ️"
case .notice:
icon = "📖"
case .warning:
icon = "⚠️"
case .critical:
icon = "⚡"
case .error:
icon = "🔥"
}
var stream = self.stream
stream.write("\(self.timestamp()) \(icon) \(level) \(self.label) :\(prettyMetadata.map { " \($0)" } ?? "") \(message)\n")
}`
Here's a sample output.
2021-04-29T15:27:58-0500 🔥 error myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 not enough data. missing business account
2021-04-29T15:27:58-0500 🐛 debug myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 user-id=testmeta Testing log levels..
2021-04-29T15:27:58-0500 ℹ️ info myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 Testing log levels..
2021-04-29T15:27:58-0500 📖 notice myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 Testing log levels..
2021-04-29T15:27:58-0500 ⚠️ warning myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 Testing log levels..
2021-04-29T15:27:58-0500 ⚡ critical myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 user-id=testmeta Testing log levels..
2021-04-29T15:27:58-0500 🔥 error myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 Testing log levels..
It helps to just do a quick scan in your Xcode console and find errors because they're on Fyre.. 🔥
If so, I can put up a pull request on that class. It might be nice to enable or disable it, but I wasn't sure how to pull that off quickly so I duplicated that class in my local project.
The text was updated successfully, but these errors were encountered:
Thanks for the idea but the default logger impl is the wrong place to do any such pretty printing.
I would recommend you kick off your own package and provide a LogHandler in there, we'll be happy to link to it!
The power of swift-log is people selecting a log handler backend that they see fit -- it could totally be your backend, but we do not want more than the absolute bare minimum in the default logger (meaning that yes, it is not great, but that is on purpose).
Sounds good very good points. I’ll get a quick new repo up for it. And link
it back here.
Yeah I already setup a custom logger for our own app that hits a back end
JSON service for critical and errors. It was a cheaper and easier solution
to splunk. ;-)
On Thu, Apr 29, 2021 at 19:49 ktoso ***@***.***> wrote:
Thanks for the idea but the default logger impl is the wrong place to do
any such pretty printing.
I would recommend you kick off your own package and provide a LogHandler
in there, we'll be happy to link to it!
The power of swift-log is people selecting a log handler backend that they
see fit -- it could totally be your backend, but we do not want more than
the absolute bare minimum in the default logger (meaning that yes, it is
not *great*, but that is on purpose).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#193 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC7ZXHCNXAIOOTRZBMTWQ3TLH5A3ANCNFSM432U6U3A>
.
I added some color to easily help me debug issues in my code when printing to the console.
Would there be any support for something like this? I basically modified the StreamLogHandler to add an icon before logging to the console.
Here's the rough change inside the public func log.
`public func log(level: Logger.Level,
message: Logger.Message,
metadata: Logger.Metadata?,
source: String,
file: String,
function: String,
line: UInt) {
let prettyMetadata = metadata?.isEmpty ?? true
? self.prettyMetadata
: self.prettify(self.metadata.merging(metadata!, uniquingKeysWith: { _, new in new }))
Here's a sample output.
2021-04-29T15:27:58-0500 🔥 error myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 not enough data. missing business account⚠️ warning myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 Testing log levels..
2021-04-29T15:27:58-0500 🐛 debug myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 user-id=testmeta Testing log levels..
2021-04-29T15:27:58-0500 ℹ️ info myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 Testing log levels..
2021-04-29T15:27:58-0500 📖 notice myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 Testing log levels..
2021-04-29T15:27:58-0500
2021-04-29T15:27:58-0500 ⚡ critical myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 user-id=testmeta Testing log levels..
2021-04-29T15:27:58-0500 🔥 error myAppName : appVersion=1.0 (1) - LOCAL sUuid=F8361008-6B9B-4B91-AD12-65CE0EF1E3B0 Testing log levels..
It helps to just do a quick scan in your Xcode console and find errors because they're on Fyre.. 🔥
If so, I can put up a pull request on that class. It might be nice to enable or disable it, but I wasn't sure how to pull that off quickly so I duplicated that class in my local project.
The text was updated successfully, but these errors were encountered: