Developing a Tiny Logger in Swift
Sauvik Dolui
2589

Really liked your tutorial, it offered insights into some very interesting points. However, I have a remark about your usage of the DEBUG macro. In you current implementation, you assume that you don’t want any of the log messages to be logged when the application is in any mode other than debug, which is an erroneous assumption to make. Most of the time, we expect some of the messages to be logged even if the app is NOT in DEBUG mode, so that we can check the console output later and see what went wrong. Usually, this is the case with the more critical levels of log events, like “error” and “severe”. What I suggest is something like this:

#if !DEBUG
if (event == .error || event == .severe) {
print(“\(Date().toString()) \(event.rawValue) [\(sourceFileName(filePath: fileName))]: \(line) \(funcName) -> \(message)”)
}
#else
print(“\(Date().toString()) \(event.rawValue) [\(sourceFileName(filePath: fileName))]: \(line) \(funcName) -> \(message)”)
#endif
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.