EXPLogger

Simple and lightweight logger for Swift


Keywords
cocoapod, cocoapod-pod, debug, debugging, ios, logging, logging-library, macos, swift, swift-framework, swift-library, swift4, tvos
License
MIT
Install
pod try EXPLogger

Documentation

EXPLogger

A lightweight and simple logger for Swift projects

Colorful, flexible, lightweight logging for Swift 4.


Navigation


Example

Example of output in Xcode Console:

23:21:37.635 [VERBOSE] [OrdersVC.viewDidLoad():24] - Some non important information
23:21:37.636 [DEBUG] [OrdersVC.viewDidLoad():25] - Some useful information just to debugging
23:21:37.636 [INFO] [OrdersVC.viewDidLoad():26] - Useful information, etc
23:21:37.636 [WARNING] [OrdersVC.viewDidLoad():27] - Not a good information
23:21:37.636 [ERROR] [OrdersVC.viewDidLoad():28] - Some important error
23:21:37.636 [CRITICAL] [OrdersVC.viewDidLoad():29] - Something went so wrong with critical priority

Or one more example:

Example of output

  • Now there are some problems with displaying colors from the Xcode 8, so they are temporarily replaced by Emoji (if u want, ofc.

Installation

Cocoapods

To use EXPLogger with CocoaPods add this to your Podfile:

pod 'EXPLogger', '~> 1.0.3'

Then run pod install. For details of the installation and usage of CocoaPods, visit it's official web site.

Swift Package Manager

Will be available soon.

Carthage

Will be available soon.


Usage

This quick start method is intended just to get you up and running with the EXPLogger. You should however use the advanced usage below to get the most out of this library.

Add this code at the top of your AppDelegate.swift to be able to use EXPLogger in your whole project. Or just use it in your individual classes. It's up to you.

  1. Import
import EXPLogger
  1. Declare an instance of the logger
let log = EXPLogger.self

In the AppDelegate method didFinishLaunchingWithOptions() add the EXPLogger log targets (console, file, etc.). And it's ready to use.

  1. Set up logger
// add log targets (important! at least one is needed)
let console = ConsoleTarget() // xcode console

// add the targets to log
log.addTarget(console)

// log anything you want in your whole project!
log.verbose("Some non important information that can be easily skipped")
log.debug("Some useful information just to debugging")
log.info("Useful information, etc")
log.warning("Not a good information")
log.error("Some error")
log.critical("Something went so wrong with critical prior")

The different methods set the log level of the message. EXPLogger will only print messages with a log level that is greater to or equal to it's current log level setting. So a logger with a level of .error will only output log messages with a level of .error, or .critical.

Log Anything

You can log simple strings:

log.debug("Hi there, I'm EXPLogger!")

Or just anything you want, for example:

log.debug((4, 2, 1, 0, 5)) // array
log.debug(true) // boolean
log.debug(CGPoint(x: 1.1, y: 2.2)) // something like this
log.debug(Enum.Option) // enums

Advanced Usage

EXPLogger allows for much greater control and flexibility.

EXPlogger can be configured to deliver log messages to a variety of destinations. Using the basic setup above, the logger will output log messages to the standard Xcode debug console just in a few lines of setup.

  • Here's an example of configuring the logger with some additional settings.
// add log targets
let console = ConsoleTarget() // xcode console

console.showDate = false // (default is true)
console.showLogTag = true // (default is true)
console.showFileName = true // (default is true)
console.showFunctionName = false // (default is true)
console.showThreadName = true // (default is false) *will be available soon
console.showLineNumber = true // (default is true)
console.showLevel = false // (default is true)
console.showFileSuffix = true // (default is true)
console.enableColors = false // (default is false) *not working for now in Xcode 8
console.defaultDateFormat = "HH:mm:ss" // (default is "HH:mm:ss.SSS")
console.defaultTimeZone = "UTC" // (default will be TimeZone.Current)

// add the targets to log
log.addTarget(console)

// log anything you want in your whole project!
...

If you don't configure these functions, EXPLogger will work based on default values.

  • Here's an example of configuring the logger with some additional destinations.

Will be filled soon.


Documentation

Will be filled soon.


Communication and Help


Changelog

See CHANGELOG.


License

EXPLogger Library is released under the MIT License.