Features (Package version)
- Ease of use in simplest case.
- Supports both terminal and Cocoa based applications.
- Logging to Xcode console.
- Output to XML format file.
- Rolling file output.
- Setting and testing log levels in code.
- Limited in-code reconfiguration.
- Uses same XML format configuration as *log4j*.
- Schema support for configuration file using RELAX-NG and Schematron.
Extra Features (MacOS version)
- Logging to window within application (Uses SwiftIU)
It does not support the following:
- Network Logging (using NSLogger).
- Asynchronous logging.
- Auto-reload of configuration.
- Logging parameters using closures.
LoggerFactory is the primary class for the logging system. Always make sure that you instantiate this class to
use it. For example a simple way would be:
extension LoggerFactory {
static func setLoggingSystem( forClass: String, file: String = "hestia-configuration.xml" ) -> Logger? {
var masterLoggerFactory: LoggerFactory!
do {
if masterLoggerFactory == nil {
let embeddedConfigPath = Bundle.main.resourcePath!
masterLoggerFactory = LoggerFactory.sharedInstance
try masterLoggerFactory.configure( from: file,
inFolder: embeddedConfigPath,
using: masterLoggerFactory )
}
let logger = try masterLoggerFactory.getLogger( name: forClass )
return logger
} catch let err as LoggerError {
print( err )
return nil
} catch {
print( "Unknown error when setting logging system" )
return nil
}
}
}
Each class that requires a logger might declare it:
class aClass {
public var logger: Logger!
init( configFileName: String ) {
logger = LoggerFactory.setLoggingSystem( forClass: self.className, file: configFileName )
logger.debug( "Root class \(self.className) has loaded logger with \(configFileName)" )
}
}
Assuming a configuration file (and a project name HestiaTest):
<configuration xmlns="http://www.hsfr.org.uk/Schema/Hestia">
<appenders>
<appender name="console" class="StdOutAppender">
<layout class="PatternLayout">
<param name="ConversionPattern" value="%d{MM/dd/yyyy hh:mm}: %p %F [%L] %M: %m"/>
</layout>
</appender>
</appenders>
<loggers>
<root>
<level value="fatal"/>
<appender-ref ref="console"/>
</root>
<logger name="HestiaTest.aClass">
<level value="info"/>
<appender-ref ref="console"/>
</logger>
</loggers>
</configuration>
Typical output would typically be
01/06/2018 05:29: Debug aClass.swift [54] init(configFileName:): Root class init has loaded logger with hestia.xml