Game development for Apple platforms

Starting to use Apple unified logging

print-based logging is fine but at some point it starts to get limiting. You soon start wanting to know what component is outputting logs, and maybe have some type of log persistence after your application is stopped.

Perusing the docs, it looks like the Apple-sanctioned way to do logging is via the Logger class.

The initializer, however, requires some strings that I'm not a fan of manually specifying:

init(subsystem: String, category: String)

So to make it a bit less manual:

fileprivate let subsystem = Bundle.main.bundleIdentifier!

class Logging<T>
{
    public lazy var log: Logger = {
        Logger(subsystem: subsystem, category: String(describing: T.self))
    }()
}

And now whenever I want to get a log, I can do (on a class definition):

let log = Logging<MyClass>().log

and subsequently:

log.debug("Hello World")

For now, this is all the time I'm willing to dedicate to logging. But I figure - better stop using print sooner than later. And when more advanced use cases come up, at least it will not be necessary to go over the codebase, and eradicate all calls to print.

#logging #os_log #short-and-sweet