Logma
is a convenient and customizable library for log processing.
It can write logs using the 5-levels of logging (Debug, Info, Notice, Error, and Fault) defined by the Apple OS log system.
- iOS 14.0+
dependencies: [
.package(url: "https://github.com/wlsdms0122/Logma.git", .upToNextMajor("1.2.0"))
]
Logma
is a library that wraps the log system for customization.
If you want to write logs in your app, you can use Logma
's basic API for printing.
To use Logma
, you should configure the printers first:
Logma.configure([
// Any printers.
])
Printer
is a simple protocol for printing logs. You can define your own log printer or use the default printer ConsolePrinter
provided by Logma:
protocol Printer {
func print(_ message: Any, userInfo: [Logma.Key: Any], level: Logma.Level)
}
After configuring Logma
, you can use the following 5-level log APIs:
static func debug(_:userInfo:)
static func info(_:userInfo:)
static func notice(_:userInfo:)
static func error(_:userInfo:)
static func fault(_:userInfo:)
For example, if you want to write log using Apple's Logger, you can define LoggerPrinter
adopt Printer
protocol.
// LoggerPrinter.swift
import OSLog
struct LoggerPrinter: Printer {
let logger = Logger()
func print(_ message: Any, userInfo: [Logma.Key: Any], level: Logma.Level) {
let message = ...
switch level {
case .debug:
logger.debug(message)
...
}
}
}
// AppDelegate.swift
import Logma
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Logma.configure([
LoggerPrinter()
])
...
}
}
Any ideas, issues, opinions are welcome.
Logma
is available under the MIT license. See the LICENSE file for more info.