A lightweight Swift logger, uses `print` in development and `NSLog` in production. Support colourful and formatted output.

Related tags

Logging Loggerithm
Overview

Loggerithm

CI Status CocoaPods Version Carthage compatible License Platform

A lightweight Swift logger, uses print in Debug and NSLog in Production with colourful output.

Why

In Swift, we usually use print to log information into console. However, it doesn't log anything in production version.

Thus we want to use NSLog in production but still want the efficiency of print in development. (print is faster than NSLog).

This project started more than half a year ago, named ZHSwiftLogger. At that time, no other Swift loggers provided this functionality. So I developped this logger for my personal usage.

Nowadays, we have more and more great Swift loggers. While, Loggerithm is lightweight, pretty straightforward and handy to use.

Features

  • Use print in Debug and NSLog in Production.
  • Formatted output, just like NSLog.
  • Log level Support.
  • Colorful output and color customization.
  • Comprehensive Unit Test Coverage.

Requirements

  • iOS 8.0+ / Mac OS X 10.9+
  • Xcode 7.0

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

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

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

pod 'Loggerithm', '~> 1.5'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

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

github "honghaoz/Loggerithm" ~> 1.5

Run carthage update to build the framework and drag the built Loggerithm.framework into your Xcode project.

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but Loggerithm does support its use on supported platforms.

Once you have your Swift package set up, adding Loggerithm as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .Package(url: "https://github.com/honghaoz/Loggerithm.git", majorVersion: 1)
]

Manually

  • Add Swift files in Source folder into your project

  • Add DEBUG flag to Swift Compiler:

    • Open project setting
    • Select your target
    • Go to Build Settings
    • Search Swift
    • Under Swift Compiler - Custom Flags section, in Other Swift Flags line, add -D DEBUG

Colorful Output Support

Need XcodeColors plugin installed.

XcodeColors Installation

Setup Environment Variable

Once XcodeColors is installed and loaded properly. To let logger automatically turn on, you need to add "XcodeColors" = "YES" environment variable to your build scheme.

This can be done in following way:

  • Under target selection, click Edit Scheme...
  • Under Arguments tab, in Environment Variables, hit + to add a new environment variable with name "XcodeColors" and value "YES".

You can also manually force to turn on/off colorful output by modifying useColorfulLog property

Usage

Basic

If you are using CocoaPods to integrate Loggerithm. Import Loggerithm first:

import Loggerithm
var log = Loggerithm()

// Usage example
log.verbose("Verbose message...")
log.debug("Debug message...")
log.info("Info message...")
log.warning("Warning message...")
log.error("Error message...")

Results:

Log Levels

By default, logLevel is .Verbose for development and .Warning for Production.

LogLevel from low to high is

.All

.Verbose

.Debug

.Info

.Warning

.Error

.Off

Logging with level lower than logLevel will be ignored.

Advanced

Fields

Log string containts 5 fields, format is:

y-MM-dd HH:mm:ss.SSS [LogLevel] [FileName:LineNumber] functionName: message

All logging fields can be turned on/off:

var log = Loggerithm()

log.showDateTime = false
log.info("date time is turned off.")

log.showLineNumber = false
log.info("Line number is turned off.")

log.showFileName = false
log.info("File name is turned off.")

log.showFunctionName = false
log.info("Function name is turned off.")

log.showLogLevel = false
log.info("Log level is turned off.")

log.emptyLine()
log.info("Restoring to full format...")

Results:

Formatted Output

var log = Loggerithm()
log.verbose("I can use format: %d + %d = %d", args: 1, 1, 2)

Results:

Color Output

Switch On/Off

See Installation/Colorful Output Support for more detail.

You can modify useColorfulLog to turn on/off colorful output.

log.useColorfulLog = false
log.info("Color is turned off.")
log.useColorfulLog = true
log.info("Color is turned on.")

Note, If you don't have XcodeColors plugin installed but leaving useColorfulLog turned on, this will result in hidden color setting code to be visible:

�[fg190,190,190;2015-08-14 16:55:34.075 [Verbose] [ViewController.swift:34] viewDidLoad(): Verbose message...�[;
�[fg60,161,202;2015-08-14 16:55:34.076 [Debug] [ViewController.swift:35] viewDidLoad(): Debug message...�[;

Color Customization

var log = Loggerithm()

log.verboseColor = UIColor.grayColor()
log.debugColor = UIColor.greenColor()
log.infoColor = UIColor.yellowColor()
log.warningColor = UIColor.orangeColor()
log.errorColor = UIColor.redColor()

log.verbose("Verbose message...")
log.debug("Debug message...")
log.info("Info message...")
log.warning("Warning message...")
log.error("Error message...")

Results:

The MIT License (MIT)

The MIT License (MIT) Copyright (c) 2014 Honghao Zhang (张宏昊)

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
  • Loggerithm not working on iOS7

    Loggerithm not working on iOS7

    Hi, I'm trying to install Loggerithm via CocoaPods but I get the following error when I run 'pod install'

    Updating local specs repositories
    Analyzing dependencies
    dyld: warning, LC_RPATH @executable_path/../lib in /Applications/Xcode.app/Contents/Frameworks/IDEFoundation.framework/Versions/A/../../../../Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib being ignored in restricted program because of @executable_path
    dyld: warning, LC_RPATH @executable_path/../Frameworks in /Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/MacOS/Xcode3Core being ignored in restricted program because of @executable_path
    [!] Unable to satisfy the following requirements:
    
    - `Loggerithm` required by `Podfile`
    

    I'm running on OS X El Capitan 10.11 (15A244d) & Xcode 6.4 (6E35b) I am using CocoaPods with many other dependencies and never get that issue.

    Here is the most relevant information I fond about this issue : http://stackoverflow.com/questions/31778963/dyld-warnings-from-using-cocoapods

    The thing is that I don't have any problem with these pods :

    • pod 'Parse'
    • pod 'Appirater'
    • pod 'KVNProgress'
    • pod 'MaterialKit'
    • pod 'YLMoment'
    opened by MatthieuTnsc 12
  • Cocoapods integration

    Cocoapods integration

    I am trying to use this with XCode 6.2 and Cocoapods 0.36.0 with no success, any idea how to make this works, I am importing the using import ZHSwiftLogger

    but the methods are not detected.

    opened by chrux 7
  • No output in XCode after installing

    No output in XCode after installing

    Just installed version 1.3.2.. the cocoapods install was successful. And I specified the DEBUG swift compiler but I don't see any output in XCode.

    Please let me know if you need any more info from me.

    opened by sola92 5
  • pod install faild

    pod install faild

    I use command pod install to install Loggerithm as Readme says, but the console logs Unable to find a pod with name matchingLoggerithm'`. It seems something wrong happend to Loggerithm with cocoapods.

    opened by dabing1022 5
  • Carthage support, Swift 3.1 migration and other minor improvements.

    Carthage support, Swift 3.1 migration and other minor improvements.

    • tvOS and watchOS support.
    • Carthage support.
    • Swift 3.1 migration.
    • Added a project that includes the framework and test targets for each supported platform and also the Demo for iOS.
    • Bumped the pod version.
    • Updated the Travis CI config.
    opened by arturgrigor 3
  • DEBUG mode for Release configuration

    DEBUG mode for Release configuration

    Hi

    There is problems with cocoapod specs. when i add this dependency. DEBUG flag was added to release configuration as well.

    In pod spec you have line "OTHER_SWIFT_FLAGS": "-D DEBUG"

    i guess it should be "OTHER_SWIFT_FLAGS[config=Debug]": "-D DEBUG"

    opened by Latyntsev 2
  • Inaccurate info in the Readme.

    Inaccurate info in the Readme.

    The Readme states XCGLogger only uses println() and doesn't use NSLog(). This is inaccurate. NSLog support was added as an option using the XCGNSLogDestination class.

    opened by DaveWoodCom 1
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 0
Releases(1.5)
Owner
HongHao Zhang
🔨
HongHao Zhang
Logger - This package is a thin wrapper for `os.Logger`

Logger This package is a thin wrapper for os.Logger. Usage Define os.Logger as an extension of Logger with the property name of the string that the sy

treastrain / Tanaka Ryoga 5 Jul 1, 2022
Easy to use and lightweight logger for iOS, macOS, tvOS, watchOS and Linux in Swift.

Lighty Easy to use and lightweight logger for iOS, macOS, tvOS, watchOS and Linux in Swift. Screenshots Requirements Lighty Version Minimum iOS Target

Abdullah Selek 51 Dec 21, 2022
A fancy logger yet lightweight, and configurable. 🖨

?? ?? Important: Printer can only print console logs if you're running an app in the Simulator. If you're running in a real device it will not print a

Hemang 66 Dec 7, 2022
XCLog is a Swift extension that helps you print something in console when debugging your projects.

XCLog XCLog is a Swift extension that helps you print something in console when debugging your projects. Installation Open Xcode > File > Add Packages

null 1 Jan 9, 2022
Automate box any value! Print log without any format control symbol! Change debug habit thoroughly!

LxDBAnything Automate box any value! Print log without any format control symbol! Change debug habit thoroughly! Installation You only need drag LxD

DeveloperLx 433 Sep 7, 2022
Delightful console output for Swift developers.

Rainbow adds text color, background color and style for console and command line output in Swift. It is born for cross-platform software logging in te

Wei Wang 1.7k Dec 31, 2022
A custom logger implementation and Task Local helper for swift-log

LGNLog A custom logger implementation and TaskLocal helper for Swift-Log. Why and how This package provides two and a half things (and a small bonus):

17:11 Games 0 Oct 26, 2021
Tracker - A simple location logger app written in Swift and MVVM architecture

Tracker - A simple location logger app written in Swift and MVVM architecture

Loay Ashraf 1 Mar 12, 2022
A simple logger for your swift applications.

AHQSLogger A simple logging system. Usage import AHQSLogger Use the following methods for loggging. Logging an information / debug You can log a simp

André Henrique da Silva 0 Dec 29, 2021
A network logger for iOS and macOS projects.

OkLog for iOS and macOS OkLog-Swift is a network logger written in Swift highly inspired by simonpercic's original OkLog implementation to be used in

Diego Trevisan Lara 18 Dec 24, 2021
Bugfender SDK for iOS, a remote logger tailor-made for mobile

Bugfender SDK for iOS Bugfender is a cloud service to collect mobile application logs. Developers can control log sending programmatically and manuall

Bugfender 69 Dec 4, 2022
LogDog is designed to work out of the box, you can use the pre-configured logger anytime, anywhere

LogDog user-friendly logging apple/swift-log api compatible Usage LogDog is designed to work out of the box, you can use the pre-configured logger any

Luo Xiu 21 Aug 14, 2022
Logger for Xcode

CSwiftLog Usage Log.log("Message text without category") Log.my.log("Message text with custom category") Log.network.log("Message text with network ca

Andrew Firsenko 2 Nov 29, 2021
Simple network activity logger for iOS

Reqres is a simple library for logging all requests and responses in your app. It supports Alamofire and also requests made via native NSURLSession. ⬆

Ackee 85 Aug 21, 2022
Stock tradings Logger app for iOS

Stock Logger Contributor: Name: Prof. Darren Takaki Author: Name: Ibrahim (Wusiman Yibulayin) Student ID: 0728356 Table of contents Description Gettin

null 2 Jul 28, 2022
An Alamofire network activity logger view

?? AlamofireLogbook An Alamofire network activity logger view Installation AlamofireLogbook is available through CocoaPods. To install it, simply add

Michael Daoud 12 Oct 30, 2019
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
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
📱💬🚦 TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.

TinyConsole TinyConsole is a tiny log console to display information while using your iOS app and written in Swift. Usage Wrap your Main ViewControlle

Devran Cosmo Uenal 2k Jan 3, 2023