Logg 1.1.0

Logg 1.1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release May 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Juanjo Arreola.


Downloads

Total127
Week32
Month91

Installs

Apps9
Apps WeekApps This Week 5
Test Targets1
Test WeekTests This week 1
powered by Segment

GitHub

Stars0
Watchers1
Forks0
Issues0
Contributors1
Pull Requests0

Code

Files8
LOCLines of Code 202


Logg 1.1.0

  • By
  • Juanjo Arreola

A logging framework for swift

Usage

Log.debug("Current loggers: \(Log.loggers)")
Log.warn("Using formatter: \(Log.loggers.first!.formatter)")
Log.error(TestError.invalid)
Log.severe("some error")
Prints:
04-21 13:04:30.040 LoggTests.swift testFileLogger() [14] ℹ️ Debug: Current loggers: [Logg.ConsoleLogger]
04-21 13:04:30.041 LoggTests.swift testFileLogger() [15] ⚠️ Warning: Using formatter: Logg.DefaultFormatter
04-21 13:04:30.041 LoggTests.swift testFileLogger() [16] ❗ Error: invalid
04-21 13:04:30.041 LoggTests.swift testFileLogger() [17] ‼️ Severe: some error

Configuration

Log is the class that dispatch the messages to all the loggers, you can configure this loggers modifying the loggers static property:

if debug {
  Log.loggers = [ConsoleLogger()]
} else {
  Log.loggers = [CustomLogger(level: [.error, .severe])]
}

Each logger has a property named level that you can customize:

let consoleLogger = Log.loggers.first
consoleLogger?.level = [.debug, .warning]

The level is an OptionSet with 4 basic values: debug, warning, error, severe and additionally all and none

Logger

You can create and register your own loggers, just implement the Logger protocol and add an instance to the loggers static property of the Log class. The Logger protocol defines a couple of properties, level and formatter, and four functions: debug, warn, error and severe that correspond to the log levels

Formatter

You can create your own formatter and use it with the loggers you want, just create a class that implements the Formatter protocol and assign it to the logger

let consoleLogger = Log.loggers.first
consoleLogger?.formatter = CustomFormatter()