An extensible logging framework for Swift

Related tags

Logging Log
Overview

Travis Status CocoaPods compatible Carthage compatible Platform

Log is a powerful logging framework that provides built-in themes and formatters, and a nice API to define your owns.

Get the most out of Log by installing XcodeColors and KZLinkedConsole

Usage β€’ Installation β€’ License

Usage

The basics

  • Use Log just as you would use print.
let Log = Logger()

Log.trace("Called!!!")
Log.debug("Who is self:", self)
Log.info(some, objects, here)
Log.warning(one, two, three, separator: " - ")
Log.error(error, terminator: "😱😱😱\n")

  • Disable Log by setting enabled to false:
Log.enabled = false
  • Define a minimum level of severity to only print the messages with a greater or equal severity:
Log.minLevel = .warning

The severity levels are trace, debug, info, warning, and error.

Customization

  • Create your own Logger by changing its Theme and/or Formatter.

A suggested way of doing it is by extending Formatters and Themes:

extension Formatters {
    static let detailed = Formatter("[%@] %@.%@:%@ %@: %@", [
        .date("yyyy-MM-dd HH:mm:ss.SSS"),
        .file(fullPath: false, fileExtension: false),
        .function,
        .line,
        .level,
        .message
    ])
}

extension Themes {
    static let tomorrowNight = Theme(
        trace:   "#C5C8C6",
        debug:   "#81A2BE",
        info:    "#B5BD68",
        warning: "#F0C674",
        error:   "#CC6666"
    )
}
let Log = Logger(formatter: .detailed, theme: .tomorrowNight)

See the built-in formatters and themes for more examples.

Tip: Log.format and Log.colors can be useful to visually debug your logger.

Nothing prevents you from creating as many loggers as you want!

let Basic = Logger(formatter: .default, theme: nil)
let Short = Logger(
    formatter: Formatter("%@: %@", .level, .message),
    theme:     .tomorrowNightEighties,
    minLevel:  .info
)

  • Turn off the colors by setting the theme to nil:
Log.theme = nil

Advanced

Include a custom Block component in your formatter to print its result in every log message:

struct User {
    static func token() -> Int {
        return NSUserDefaults.standardUserDefaults.integerForKey("token")
    }
}

Log.formatter = Formatter("[%@] %@: %@", .block(User.token), .level, .message)

Installation

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Log into your Xcode project using Carthage, specify it in your Cartfile:

github "delba/Log"

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

You can install it with the following command:

$ gem install cocoapods

To integrate Log into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

pod 'Log'

License

Copyright (c) 2015-2016 Damien (http://delba.io)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Update to Swift 3 and recommended project settings

    Update to Swift 3 and recommended project settings

    Just tried out my project using Log with Swift 3 in the Xcode 8 Beta. Looks like there's currently no Swift 3 compatible branch here. It'd be great if you could merge this into a currently non existent branch on your repo or make the changes yourself if you want and close this PR.

    Thanks 😊

    opened by kiliankoe 7
  • Fix Xcode 10 cannot show logs in console problem

    Fix Xcode 10 cannot show logs in console problem

    Xcode 10 cannot show logs in the console, that's because of the level comparison failed in log function (level >= minLevel always false), fix it by using raw values type "Int" for "Level"

    opened by ming-chu 5
  • Consider Removing XcodeColor info from log

    Consider Removing XcodeColor info from log

    Hi, Unfortunately Xcode won't support plugins anymore and we are left with no XcodeColor. Log still tries to add color info to console logs and that makes an ugly (and sad) console.

    I thing the colorization should become optional (with room left for possible future support for XcodeColor)

    Thoughts?

    opened by mohpor 4
  • Log messages not being displayed in XCode debug console

    Log messages not being displayed in XCode debug console

    Hey @delba, are you still maintaining this library? I am having odd issue now where logs print inconsistently, I can't tell if this is an issue newly introduced in XCode 10, or if it happened due to me updating iOS. Have you seen anything similar in any of your projects?

    opened by jakerockland 3
  • Logger instance

    Logger instance

    Hi Damien, the library is great, thanks. I have one suggestion for the last line in Logger.swift: public let Log = Logger(formatter: .Default, theme: .Default)

    First thing is, the name of an instance should not be capitalized? Would public let log = be better? Also, what do you think about leaving the responsibility of creating a Logger instance to the user, by deleting that line?

    opened by yichizhang 3
  • Add support for Swift Package Manager

    Add support for Swift Package Manager

    Xcode complained about some missing symbols which were resolved by the Foundation imports. Besides that it seems to work fine now for use with Xcode 11's SwiftPM support 😊

    opened by kiliankoe 2
  • Log severity with Emoji

    Log severity with Emoji

    I want my logger to include the following emoji symbols with the log: ERROR: ❗️ WARNING: ❕

    In other words, whenever an error is logged, the logger will also include "❗️" in the log.

    Is that possible by customizing the formatter, or does it require a deeper change?

    opened by noamtamim 2
  • Type of expression is ambiguous without more context

    Type of expression is ambiguous without more context

    Hi,

    Since Swift3 update I have this strange behaviour Type of expression is ambiguous without more context with that simple code:

    import Log
    
    let Log = Logger(formatter: .Detailed,
                     theme: .TomorrowNight,
                     minLevel: .Trace)
    
    extension Formatters {
        static let Detailed = Formatter("[%@] %@.%@:%@ %@: %@", [ //Error is just here
            .Date("yyyy-MM-dd HH:mm:ss.SSS"),
            .File(fullPath: false, fileExtension: false),
            .Function,
            .Line,
            .Level,
            .Message
            ])
    }
    
    extension Themes {
        static let TomorrowNight = Theme(
            trace:   "#C5C8C6",
            debug:   "#81A2BE",
            info:    "#B5BD68",
            warning: "#F0C674",
            error:   "#CC6666"
        )
    }
    

    Any help would be appreciated. Vivien

    opened by VivienGiraud 2
  • Possibility to attach log handler

    Possibility to attach log handler

    I am wondering whether there is a built-in mechanism for attaching additional code that handles a log. I've recently started using a cloud logging framework and would like to attach the frameworks logging call to all my existing Log.*("...") calls. Is there an intended attachment point that I have overseen or is there no option without modifying your code?

    Thanks in advance Benno

    opened by bennol 2
  • codebeat badge

    codebeat badge

    Is it fine to add codebeat badge to README?

    codebeat is automated code review tool for Swift,Ruby,Go & Python that helps get instant feedback on code quality.

    "Quick wins" suggested by codebeat could be a nice candidate for a pull request and help other developers become contributors.

    FYI. To be fully open and honest. I'm co-founder of codebeat.

    opened by korzonek 2
  • Carthage + Xcode 10.2.1 : Task failed with exit code 65

    Carthage + Xcode 10.2.1 : Task failed with exit code 65

    Step to reproduce :

    Run carthage update --platform iOS on your project Get this error :

    *** Building scheme "Log iOS" in Log.xcodeproj
    Build Failed
    Task failed with exit code 65....
    This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details:
    

    Did someone found a solution ?

    opened by JoseTovar94 1
  • Log statements don't have different colors

    Log statements don't have different colors

    Environment:

    • Swift 5
    • Xcode 11.3.1

    Problem: I implement the logger using the various levels of severity however all the log statements in the console are still white. I have tried changing themes and yet I still cannot have TRACE, DEBUG, INFO, WARNING, or ERROR to appear in the console with the proper colors.

    Example Logger Setup:

        // MARK: Logging
        
        private lazy var log = Logger(formatter: .default, theme: .tomorrowNightEighties, minLevel: .trace)
    

    Example Console Output:

    Screen Shot 2020-01-16 at 1 14 28 PM

    opened by adamisrafil 1
  • 2.0 can't be depended on with SwiftPM

    2.0 can't be depended on with SwiftPM

    Hi, unfortunately SwiftPM is currently unable to depend on this package @ 2.0 due to the naming of the version numbers.

    The previous ones are all prefixed with 'v', v0.5, v1.0, ... And then it's just '2.0'. Obviously this should be improved in SwiftPM, but it would be a quick and easy fix here until that happens 😊

    opened by kiliankoe 1
  • Add support for Emojis

    Add support for Emojis

    As you know, Apple removed support for XCode plugins in 2016, and we need some way to color code the logs. So I have added a provision to setup emojis for log levels. Please go through the code, and let me know what you think.

    I have not updated readme or version number, yet. I'll update it, if this change is merged.

    opened by surajthomask 0
  • Logger instance hook for logging to different locations.

    Logger instance hook for logging to different locations.

    This is definitely one of the better and more flexible logging frameworks for client side swift. Awesome work.

    It would be great, however, to add an abstraction which will allow you to assign multiple output locations. E.G., Instead of just logging to standard output, it would be nice to be able to take the same record and just send it to another logging service via https.

    Happy to open a PR for this when I get the time.

    enhancement 
    opened by thedodd 1
Owner
Damien
Damien
CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant

CleanroomLogger CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant. The API provided by Cleanro

null 1.3k Dec 8, 2022
A logging backend for swift-log that sends logging messages to Logstash (eg. the ELK stack)

LoggingELK LoggingELK is a logging backend library for Apple's swift-log The LoggingELK library provides a logging backend for Apple's apple/swift-log

null 17 Nov 15, 2022
JustLog brings logging on iOS to the next level. It supports console, file and remote Logstash logging via TCP socket with no effort. Support for logz.io available.

JustLog JustLog takes logging on iOS to the next level. It supports console, file and remote Logstash logging via TCP socket with no effort. Support f

Just Eat 509 Dec 10, 2022
A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

Kitura 174 Nov 30, 2022
A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

Kitura 174 Nov 30, 2022
A powerful input-agnostic swift logging framework made to speed up development with maximum readability.

The Swift logging framework. Atlantis is an extremely powerful logging framework that I've created for everyday use, including enterprise development

Andrew Aquino 199 Jan 2, 2023
Simple, lightweight and flexible debug logging framework written in Swift

AELog Simple, lightweight and flexible debug logging minion written in Swift If you find yourself in upcoming statements, then you probably want to us

Marko Tadić 28 Jul 6, 2022
A fast & simple, yet powerful & flexible logging framework for Mac and iOS

CocoaLumberjack CocoaLumberjack is a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS. How to get started Fir

null 12.9k Jan 9, 2023
Convenient & secure logging during development & release in Swift 3, 4 & 5

Colorful, flexible, lightweight logging for Swift 3, Swift 4 & Swift 5. Great for development & release with support for Console, File & cloud platfor

SwiftyBeaver 5.6k Jan 4, 2023
Willow is a powerful, yet lightweight logging library written in Swift.

Willow Willow is a powerful, yet lightweight logging library written in Swift. Features Requirements Migration Guides Communication Installation Cocoa

Nike Inc. 1.3k Nov 16, 2022
Swift Logging Utility for Xcode & Google Docs

QorumLogs Swift Logging Utility in Xcode & Google Docs

Goktug Yilmaz 777 Jul 15, 2022
TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.

Please star this github repository to stay up to date. TraceLog Introduction TraceLog is a highly configurable, flexible, portable, and simple to use

Tony Stone 52 Oct 28, 2022
A flexible logging library written in Swift

Puppy Puppy is a flexible logging library written in Swift ?? It supports multiple transports(console, file, syslog, and oslog) as loggers. It not onl

Koichi Yokota 92 Dec 29, 2022
Logging utility for Swift and Objective C

Swell - Swift Logging A logging utility for Swift and Objective C. ##Features Turn on logging during development, turn them off when building for the

Hubert Rabago 361 Jun 29, 2022
Most natural Swift logging

Evergreen Most natural Swift logging Evergreen is a logging framework written in Swift. It is designed to work just as you would expect, yet so versat

Nils Leif Fischer 72 Aug 12, 2022
Spy is a flexible, lightweight, multiplatform logging utility written in pure Swift.

Spy is a flexible, lightweight, multiplatform logging utility written in pure Swift. It allows to log with different levels and on different channels. You can define what levels and channels actually are.

AppUnite Sp. z o.o. Spk. 12 Jul 28, 2021
A simple logging package for Swift

OhMyLog OhMyLog is a simple logging package for Swift. It supports the following features: Six logging levels ( ?? , ?? , ?? , ⚠️ , ?? , ?? ) Display

Junhao Wang 1 Jan 10, 2022
Simple logging for simples needs.

Simple logging for simples needs.

native.dev.br 0 May 30, 2022
Class for logging excessive blocking on the main thread

Watchdog Class for logging excessive blocking on the main thread. It watches the main thread and checks if it doesn’t get blocked for more than define

Wojtek Lukaszuk 1.8k Dec 6, 2022