Giter Site home page Giter Site logo

lumber's Introduction

lumber

A simple logger for Go.

Provides console and file loggers that support 6 log levels. The file logger supports log backup and rotation.

Usage:

Log to the default (console) logger

lumber.Error("An error message")

Create a new console logger that only logs messages of level WARN or higher

log := lumber.NewConsoleLogger(lumber.WARN)

Change the log level for a logger

log.Level(lumber.INFO)

Create a new file logger that rotates at 5000 lines (up to 9 backups) with a 100 message buffer

log := lumber.NewFileLogger("filename.log", lumber.INFO, lumber.ROTATE, 5000, 9, 100)
// or
log := lumber.NewRotateLogger("filename.log", 5000, 9)

Send messages to the log

// the log methods use fmt.Printf() syntax
log.Trace("the %s log level", "lowest")
log.Debug("")
log.Info("the default log level")
log.Warn("")
log.Error("")
log.Fatal("the %s log level", "highest")

Add a prefix to label different logs

log.Prefix("MYAPP")

Use a MultiLogger

mlog := NewMultiLogger()
mlog.AddLoggers(log1, log2)
mlog.Warn("This message goes to multiple loggers")
mlog.Close() // closes all loggers

Modes:

APPEND: Append if the file exists, otherwise create a new file

TRUNC: Open and truncate the file, regardless of whether it already exists

BACKUP: Rotate the log every time a new logger is created

ROTATE: Append if the file exists, when the log reaches maxLines rotate files

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.