Code Monkey home page Code Monkey logo

logging's Introduction

Disclaimer

Work in progress. Not ready for use.


Logging

A simple wrapper around the logrus library with a Logger interface which simplifies the logging framework. This is NOT a logging library! This is just a thin wrapper around the logrus logging library.

Motivation

Logrus provides lots of features, which can be useful while also a bit confusing or overwhelming. This library allows the use of all those features, while providing a limited interface to keep the logging portion as simple as possible.

The interfaces supports only 3 levels of logging:

  • Debug
  • Info
  • Error

This was inspired by Dave Cheney's thoughts on logging. Although Dave Cheney recommends the use of only 2 levels, Debug and Info, this library allows the use of Error level as well to keep things a little flexible. Sometimes we do need to log Error messages.

The logging levels also have their corresponding f versions, i.e., Debugf, Infof, Errorf.

In addition to this, there are 2 more methods available, WithField and WithFields. These work exactly like they do in logrus.

In fact, all methods under the Logger interface pass the calls directly to the underlying Logrus methods transparently. They don't modify the log entries at all. The only modification that it does carry out is in the logging level. Since it supports only 3 logging levels, the logging level is reset to the closest one if a different one was set. This means that a log level higher than Debug is reset to Debug and a level lower than Error is reset to Error.

Usage

func main(){

    // create a new logrus logger
    logrusLogger := logrus.New()

    // setup logrus
    // - add all your favourite logrus hooks and other setup
    ...

    // create a new logger
    logger := logging.NewLogger(logrus.Logger)

    // use it as you would use logrus
    logger.Info("Hello")
    logger.Infof("%d Worlds", 3)

    logger.WithField("animal", "walrus").Info("found animal")
}

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.