Coder Social home page Coder Social logo

slimlogger's Introduction

SlimLogger

SlimLogger is a small logging utility written entirely in Swift, without any dependencies to other libraries. SlimLogger is deliberately designed to be as slim as possible. SlimLogger tries to be as lean as possible, but still flexible enough to fit the requirements for most projects.

##Features

  • Log levels - Log at different log levels. Log levels are set by log destination, not by class.
  • Log filtering - Enable logging from all your source files, or enable logging only for a list of source files. This filtering is done in the central log config class, so you don't need to edit individual source files.
  • Log formatting - The console log destination will log timestamp, level, source filename, line number and the message.
  • Injectable log destinations - Besides logging to the console, you can also inject your own custom log destination classes. Just create a class that implements a single method in the LogDestination protocol. There is already a premade log destination class for logging to the cloud service Loggly.
  • Async, serial logging - Logging is done asynchronously on a separate serial thread, making sure that log entries are printed in the correct order, without blocking the main thread.

##Installation

  1. Rename SlimLoggerConfig.template to SlimLoggerConfig.swift
  2. Add SlimLogger.swift and SlimLoggerConfig.swift to your project

##Configuration

Edit the SlimConfig struct in SlimLoggerConfig.swift

struct SlimConfig {
    // Enable or disable console logging. When releasing your app, you should set this to false.
    static let enableConsoleLogging = true

    // Log level for console logging, can be set during runtime
    static var consoleLogLevel = LogLevel.trace

    // Either let all logging through, or specify a list of enabled source files.
    // So, either let all files log:
    static let sourceFilesThatShouldLog:SourceFilesThatShouldLog = .All
    // Or let specific files log:
    static let sourceFilesThatShouldLog:SourceFilesThatShouldLog = .EnabledSourceFiles([
             "AppDelegate.swift",
             "AnotherSourceFile.swift"
    ])
    // Or don't let any class log (use to turn off all logging to for all destinations):
    static let sourceFilesThatShouldLog:SourceFilesThatShouldLog = .None
} 

##Usage

Slim.trace("message")    
Slim.debug("message")    
Slim.info("message")    
Slim.warn("message")    
Slim.error("message")    
Slim.fatal("message")    

The message does not have to be a String. It can be any object, or any expression that returns an object. However, if the type of the returned object does not implement Printable, the output would not be interesting.

##Feedback and Contribution

All feedback and contribution is very appreciated. For example, contribute with a new log destination class! Please send pull requests, create issues or just send an email to [email protected].

##License

  • Copyright (c) 2015- Mats Melke. Please see LICENSE for details.

slimlogger's People

Contributors

melke avatar simplgy avatar porterhoskins avatar rnapier avatar valeriyvan avatar

Watchers

Miha 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.