Skip to content

wlsdms0122/Logma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logma

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.

Requirements

  • iOS 14.0+

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/wlsdms0122/Logma.git", .upToNextMajor("1.2.0"))
]

Getting Started

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:)

Custom Printer

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()
        ])
        ...
    }
}

Contribution

Any ideas, issues, opinions are welcome.

License

Logma is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages