Skip to content

thatfactory/applogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

49 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Swift Xcode Platforms SPM License CI Release

AppLogger

Wrapper around Apple's Swift unified logging APIs, particularly Logger.

Provides public and private logging with an app-facing AppLogLevel abstraction, so clients do not need to import os to choose a log level. The default level is .default, which maps to OSLogType.default and shows up in Console.app without requiring debug filtering.

For more information, please refer to this WWDC20 video: Explore logging in Swift

Usage

import AppLogger

let logger = AppLogger(subsystem: "com.example.app", category: "network")

// Log public information.
logger.log("Request started")

// Log private information.
logger.log(level: .info, "Request headers: \(headers)", isPrivate: true)

// Set custom levels.
logger.log(level: .error, "Request failed: \(error.localizedDescription)")

Defaults

public struct Defaults {
    public static let subsystem = Bundle.main.bundleIdentifier ?? "AppLogger"
    public static let category = "default"
    public static let isPrivate = false
    public static let level: AppLogLevel = .default
}

AppLogLevel

public enum AppLogLevel {
    case debug
    case info
    case `default`
    case error
    case fault
}

Output

Xcode console

Xcode Sample

macOS Console app

.default, .error, and .fault logs are shown by default in the Console app. If you emit debug logs, enable Action / Include Info/Debug Messages to display them.

Console App

macOS Console app: a note on .private

Keep in mind that private information will still be visible in the Console app as clear text if the device is attached to the debugger. Apparently this is by design.

Console App Private Debugger

Integration

Xcode

Use Xcode's built-in support for SPM.

Package.swift

In your Package.swift, add AppLogger as a dependency:

dependencies: [
    .package(
        url: "https://github.com/thatfactory/applogger",
        from: "1.0.0"
    )
]

Associate the dependency with your target:

targets: [
    .target(
        name: "YourTarget",
        dependencies: [
            .product(
                name: "AppLogger",
                package: "applogger"
            )
        ]
    )
]

Run: swift build

About

Wrapper around Apple's Swift logging APIs (OSLog/Unified Logging/Logger) ๐Ÿ“’

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages