Coder Social home page Coder Social logo

oslogging's Introduction

OSLogging

SPM compatible GitHub license

OSLog logging backend for swift-log

Features

  • Configure OSLog
  • Mapping logging levels of Logger.Level to OSLogType
  • Customize metadata formatter

Instalation

Add dependency to Package.swift...

.package(url: "https://github.com/Alexander-Ignition/OSLogging", from: "1.0.0"),

... and your target

.target(name: "ExampleApp", dependencies: ["OSLogging"]),

Usage

Override LoggingSystem with default OSLog.

LoggingSystem.bootstrap { _ in OSLogHandler() }

let logger = Logger(label: "com.example.app")
logger.info("i found you!")
// 2019-10-20 08:47:35.498086+0300 ExampleApp[6533:150683] i found you!

Сhoose subsystems and categories for different parts of the application

let logger = Logger(label: "com.exaple.app") { label in
    OSLogHandler(subsystem: label, category: "auth")
}

logger.info("loose control")
// 2019-10-20 08:47:35.498582+0300 ExampleApp[6533:150683] [auth] loose control

Custom metadata format

var logger = Logger(label: "com.exaple.app") { label in
    var hanlder = OSLogHandler(subsystem: label, category: "session")
    hanlder.formatter = { metadata in
        metadata.map { "\($0):\($1)" } .joined(separator: ", ")
    }
    return hanlder
}
logger[metadataKey: "request-id"] = "1"
logger[metadataKey: "session-id"] = "a"

logger.warning("catch me if you can")
// 2019-10-20 08:47:35.499106+0300 ExampleApp[6533:150683] [session] session-id:a, request-id:1 catch me now

oslogging's People

Contributors

alexander-ignition avatar

Stargazers

 avatar

Watchers

 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.