Git Product home page Git Product logo

oslog's Introduction

OSLog Framework

The OSLog framework provides convenience wrappers around the native OSLog facilities provided by Apple.

The framework provides logging functionality via the Log class. There is one function per each log level:

  • Log.msg sends a default-level log message.
  • Log.debug sends a debug-level log message.
  • Log.info sends an info-level log message.
  • Log.error sends an error-level log message.
  • Log.fault sends a fault-level log message.

There is a static Log instance called default. This corresponds to the OSLog.default object provided by the system. There are static logging functions on the Log class that invoke the corresponding methods on Log.default object.

See Apple's documentation for OSLog for a description of the various log levels and their uses.

Client applications can provide their own instances of the Log class, specifying a custom subsystem name (in reverse DNS notation) and log category. Log instances can be initialized with a custom LogFormatter which is used to produce the string that is sent to the log. Context information relating to the source file, line of code, and source function are all provided to the LogFormatter instance.

Each Log instance can be enabled or disabled. Log instances are disabled by default. The various Log functions use the @autoclosure construct for evaluating the message to be logged. Thus if a Log instance is disabled, its messages are not evaluated. This eliminates any overhead that would be incurred by performing otherwise unnecessary string expansion.

Client applications can provide an extension to the Log class defining static Log instances for each subsystem and category. For example:

import OSLog

extension Log {
    private static let subsystem = "com.example.ExampleApp"

    static let ui = Log(subsystem: subsystem, category: "ui")
    static let network = Log(subsystem: subsystem, category: "network")
}

The app can then use these loggers as follows:

Log.ui.info("This is an info log message")

Log.network.isEnabled = false
Log.network.debug("This message will not appear as the logger is disabled")

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.