目录
目录README.md

A logging framework for swift

Cocoapods Platform License

Usage

logger.info("Current loggers: \(Log.loggers)")
logger.debug("Using formatter: \(Log.loggers.first!.formatter)")
logger.error(TestError.invalid)
logger.fault("some error")
Prints:
04-21 13:04:30.040 LoggTests.swift testFileLogger() [14] ❕ Info: Current loggers: [Logg.ConsoleLogger]
04-21 13:04:30.041 LoggTests.swift testFileLogger() [15] 🐛 Debug: 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] ‼️ Fault: 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()
关于
57.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号