Code Monkey home page Code Monkey logo

shrubbery's Introduction

Shrubbery

THGLog module.

Provides versatile logging options for Swift and Objective-C code.


Introduction

THGLog/Shrubbery is a Swift framework for logging. It provides a default instance that funnels through NSLog to the console. It also provides options to log to a textfile as well as Crashlytics. 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.
  • Macro's 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.
  • LogCrashlyticsDestination checks for the Crashlytics framework at runtime, so no hard dependencies exist.

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(.Error | .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];

...

THGLog(LogLevelError, @"value = %@", @1);

// or ...

THGLogError(@"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];

...

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

Contributions

We appreciate your contributions to all of our projects and look forward to interacting with you via Pull Requests, the issue tracker, via Twitter, etc. We're happy to help you, and to have you help us. We'll strive to answer every PR and issue and be very transparent in what we do.

When contributing code, please refer to our Dennis (https://github.com/TheHolyGrail/Dennis).

THG's Primary Contributors

Dr. Sneed (@bsneed)
Steve Riggins (@steveriggins)
Sam Grover (@samgrover)
Angelo Di Paolo (@angelodipaolo)
Cody Garvin (@migs647)
Wes Ostler (@wesostler)

License

The MIT License (MIT)

Copyright (c) 2015 Walmart, TheHolyGrail, and other Contributors

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.

shrubbery's People

Contributors

angelodipaolo avatar bsneed avatar dpettigrew avatar samgrover avatar steveriggins avatar

Watchers

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