Skip to content

Latest commit

History

History
80 lines (62 loc) 路 3.6 KB

File metadata and controls

80 lines (62 loc) 路 3.6 KB

Swift Version Xcode Version Platforms SPM DocC 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 the complete API reference and usage guide, see the AppLogger DocC documentation.

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

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