SwifterLog is a utility to create logging information at multiple levels and send this to multiple targets.
While created for Swiftfire, it is completely functional on its own and can be used in other projects as well.
It offers the following features:
- 8 different log levels
- DEBUG (0)
- INFO (1)
- NOTICE (2)
- WARNING (3)
- ERROR (4)
- CRITICAL (5)
- ALERT (6)
- EMERGENCY (7)
- Send the log information to 5 different destinations
- STDOUT (Console output in Xcode or on the command line)
- ASL (Apple System Log Facility)
- NETWORK (A -remote- destination on the network)
- CALLBACK (A callback to the application that uses SwifterLog)
- The logging information consist of 5 parts:
- General purpose ID (32 bit integer)
- Originating location
- Message from the module that placed the logging call
- A ReflectedStringConvertible protocol (implementation) is provided to allow easy logging of class members on any class instance.
A typical log entry would look as follows:
2016-05-23T12:09:03.150+0200, INFO : ffffffff, main.Swiftfire.130, Listening for M&C connections
The above line would be created by the following: (at line 130 in file “main” function of “Swiftfire”)
let log = SwifterLog.theLogger log.atLevelInfo(id: -1, source: #file.source(#function, #line), message: "Listening for M&C connections")
The id parameter can be used to differentiate between threads, sockets, objects etc.
The #file, #function and #line are standard Swift tags, the “.source()” call is a String extension that is included in SwifterLog.
In addition to the logger singleton SwifterLog also provides high performance loggers for disabled levels. For example the debug and notice levels are not usually enabled in shipping applications. But allowing these calls to remain in a shipping application will degrade performance. However with optional chaining on the
atNotice loggers the big hit on runtime performance can be avoid at a small cost. Allowing these calls to remain in the shipping code.
typealias Log = SwifterLog Log.atDebug?.log(id: socket, source: #file.source(#function, #line), message: myVar)