/ELLog

(DEPRECATED) A logging framework for Swift and Objective-C

Primary LanguageSwiftMIT LicenseMIT

ELLog

Build Status Carthage Compatible

Note: This framework has been deprecated. It is no longer being actively maintained and will not be updated for future versions of Swift or iOS.

ELLog is a framework that provides versatile logging options for Swift and Objective-C code.

Requirements

ELLog requires Swift 4 and Xcode 9.2.

Installation

Carthage

Install with Carthage by adding the framework to your project's Cartfile.

github "Electrode-iOS/ELLog"

Manual

Install manually by adding ELLog.xcodeproj to your project and configuring your target to link ELLog.framework from ELLog target.

There are two target that builds ELLog.framework.

  1. ELLog: Creates dynamically linked ELLog.framework.
  2. ELLog_static: Creates statically linked ELLog.framework.

Both targets build the same product (ELLog.framework), thus linking the same app against both ELLog and ELLog_static should be avoided.

Introduction

ELLog provides a default instance that funnels through NSLog to the console. It also provides options to log to a textfile. It's fully extensible and makes it easy to add new logging destinations.

Provides the following functionality:

  • log(level, message) - Uses Logger.defaultInstance to log to the console.
  • Macros for use in Objective-C.
  • Logger classes can be created should you want to log differently in a particular section of your app.
  • Ability to add custom destinations to a given Logger instance. Add one, or add many.
  • Ability to specify levels per destination. ie: Only log .Error level messages to Crashlytics.

Optional Features

ELLog provides optional logging to Crashlytics. See the README in Destinations/Crashlytics/README.md

Common Usage

A basic out of the box setup, log to .Debug and ultimately to the console:

log(.Debug, "HEAD KNIGHT: Ni!")

Log to a custom Logger instance:

let headKnight = Logger()

headKnight.log(.Debug, "We are the Knights Who Say... Ni!")

Configure and use a custom logger instance:

let headKnight = Logger()

// we want to log any messages that are flagged with .Error or .Debug
let shrubbery = LogCrashlyticsDestination(level: [LogLevel.Error, LogLevel.Debug])

// add it to our logger instance.
headKnight.addDestination(shrubbery)

// this will go to the Crashlytics destination.
headKnight.log(.Debug, "We are the Knights Who Say... Ni!")

// this won't go anywhere.  we didn't setup a destination for .Info.
headKnight.log(.Info, "We are the Knights Who Say... Ni!")

// this will go to the Crashlytics destination as well.
headKnight.log(.Error, "We are the Knights Who Say... Ni!")

Customize the Logger's default instance and send a log message:

// .Error log messages should go to Crashlytics, yeah?
let shrubbery = LogCrashlyticsDestination(.Error)

// Remember, defaultInstance is setup to log to console.
// Let's add a destination for Crashlytics as well.
Logger.defaultInstance.addDestination(shrubbery)

// We want this message to go to both .Debug AND .Error.
log(.Debug | .Error, "We shall say 'nee' again to you if you do not appease us.")

or...

LogTextfileDestination *gardenStore = [[LogTextfileDestination alloc] initWithFilename:@"errors.txt"];
gardenStore.level = LogLevelError;

[Logger.defaultInstance addDestination:gardenStore];

...

ELLog(ELLogLevelError, @"value = %@", @1);

// or ...

ELLogError(@"value = %@", @1);

Use a custom logging instance in Objective-C:

LogTextfileDestination *gardenStore = [[LogTextfileDestination alloc] initWithFilename:@"errors.txt"];
gardenStore.level = LogLevelError;

Logger *myLogger = [[Logger alloc] init];
[myLogger addDestination:gardenStore];

...

ELLogCustom(myLogger, LogLevelError, @"value = %@", @1);