Giter Site home page Giter Site logo

swift-log-file's Introduction

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

swift-log-file's People

Contributors

crspybits avatar ktoso avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.