diff --git a/Logger.xcodeproj/project.pbxproj b/Logger.xcodeproj/project.pbxproj index 0b36d05..bc89d56 100644 --- a/Logger.xcodeproj/project.pbxproj +++ b/Logger.xcodeproj/project.pbxproj @@ -70,6 +70,7 @@ 2ED103E02135C61100EB3683 /* FileRotateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileRotateTests.swift; sourceTree = ""; }; 2ED103E22135D3FB00EB3683 /* FileWriterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileWriterTests.swift; sourceTree = ""; }; 2ED103E42138553B00EB3683 /* DiskLoggerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiskLoggerTests.swift; sourceTree = ""; }; + 2EDA8AE8213ACCFF00FE5840 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -108,6 +109,7 @@ 2EBF4B312122AA34008E4117 = { isa = PBXGroup; children = ( + 2EDA8AE8213ACCFF00FE5840 /* README.md */, 2EBF4B3C2122AA34008E4117 /* Logger */, 2E58D35B21316C3500BEF81A /* UnitTests */, 2EBF4B3B2122AA34008E4117 /* Products */, diff --git a/README.md b/README.md index dfa4ac4..599ffcf 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,46 @@ # SwiftLogger Dependency free Logger API for Swift. + +## Motivation +Beside obvious benefit for unit testing (see `NullLogger`), having loose coupling to a logging framework makes it easy to log messages into multiple logging systems at once (see `AgregateLogger`). + +## Usage +`Logger` protocol provides simple interface utilizing log levels defined by [The Syslog Protocol - RFC5424](https://www.rfc-editor.org/info/rfc5424). + +```swift +logger.log("message", level: .emergency) +logger.log("message", level: .alert) +logger.log("message", level: .critical) +logger.log("message", level: .error) +logger.log("message", level: .warning) +logger.log("message", level: .notice) +logger.log("message", level: .informational) +logger.log("message", level: .debug) +``` + +Log calls capture time, file name, method name and line number automatically. This way it is possible to compose log messages similar to the one presented below. + +``` +2018-08-31 18:29:34.748 SwiftFile:75 method() message +``` + +## Integration with logger frameworks +You need to provide implementation for one method. + +```swift +final class CustomLogger: Logger { + + public func log(time: Date, level: LogLevel, location: String, message: @autoclosure () -> String) { + /// compose message and forward it to a logging framework + } +} +``` + +## Provided loggers +`ConsoleLogger` writes messages into the standard output. + +`NullLogger` ignores all messages with the intention to minimize observer effect. Useful for unit testing. + +`DiskLogger` writes messages into the file at specified URL with log rotation support. + +`AgregateLogger` forwards messages to all the loggers it is initialized with.