Swiftpack.co -  crspybits/swift-log-file as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
crspybits/swift-log-file
A simple file logger based on swift-log
.package(url: "https://github.com/crspybits/swift-log-file.git", from: "0.1.0")

swift-log-file

SwiftLog compatible file log handler.

This currently only supports iOS.

Example: Just logging to a file

let logFileURL = URL(/* your local log file here */)
let logger = try FileLogging.logger(label: "Foobar", localFile: logFileURL)
logger.error("Test Test Test")

Example: Logging to both the standard output (Xcode console if using Xcode) and a file.

let logFileURL = try getDocumentsDirectory().appendingPathComponent(logFileName)
let fileLogger = try FileLogging(to: logFileURL)

LoggingSystem.bootstrap { label in
    let handlers:[LogHandler] = [
        FileLogHandler(label: label, fileLogger: fileLogger),
        StreamLogHandler.standardOutput(label: label)
    ]

    return MultiplexLogHandler(handlers)
}

let logger = Logger(label: "Test")

Note in that last example, if you use LoggingSystem.bootstrap, make sure to create your Logger after the LoggingSystem.bootstrap usage (or you won't get the effects of the LoggingSystem.bootstrap).

Example: Using XCGLogger

XCGLogger supports rotating file logs amongst other features.

let logFileURL = URL(/* your local log file here */)
let xcgLogger = /* Make your XCGLogger, using logFileURL */
let logger = XCGLogging.logger(label: "Test", logger: xcgLogger)
logger.error("Test Test Test")

Example: Logging to both the standard output (Xcode console if using Xcode) and a file using XCGLogger.

let logFileURL = try getDocumentsDirectory().appendingPathComponent(logFileName)
let xcgLogger = /* Make your XCGLogger, using logFileURL */

LoggingSystem.bootstrap { label in
    let handlers:[LogHandler] = [
        XCGLoggerHandler(label: label, logger: xcgLogger),
        StreamLogHandler.standardOutput(label: label)
    ]

    return MultiplexLogHandler(handlers)
}

let logger = Logger(label: "Test")

For more examples, see the unit tests and refer to apple/swift-log's README

GitHub

link
Stars: 15
Last commit: 20 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API