Skip to content
This repository has been archived by the owner on Dec 3, 2017. It is now read-only.

Latest commit

 

History

History
100 lines (67 loc) · 2 KB

README.md

File metadata and controls

100 lines (67 loc) · 2 KB

gologit

A simple wrapper for Go "log" that provides toggle-able debug support.

NOTE: gologit is currently deprecated. Check out mlog instead.

Installation

$ go get github.com/cactus/gologit

Usage

Simplest:

import (
    "flag"
    "github.com/cactus/gologit"
)

func main() {
    debug := flag.Bool("debug", false, "Enable Debug Logging")
    flag.Parse()

    // set debug true/false
    gologit.Logger.Set(*debug)
    // this prints only if debug is true
    gologit.Logger.Debugln("Debug Logging enabled!")
}

Simple:

import (
    "flag"
    "github.com/cactus/gologit"
)

// alias exported gologit Logger to a short name for convenience
var logger = gologit.Logger

func main() {
    debug := flag.Bool("debug", false, "Enable Debug Logging")
    flag.Parse()

    logger.Set(*debug)
    logger.Debugln("Logging enabled")
}

When you don't want to share:

import (
    "flag"
    "github.com/cactus/gologit"
)

// make a new one (unique to this module)
var logger = gologit.New(false)

func main() {
    debug := flag.Bool("debug", false, "Enable Debug Logging")
    flag.Parse()

    logger.Set(*debug)
    logger.Debugln("Logging enabled")
}

Pass it like a logging potato:

import (
    "flag"
    "github.com/cactus/gologit"
)

// make a new one (unique to this module)
var logger = gologit.New(false)

func main() {
    debug := flag.Bool("debug", false, "Enable Debug Logging")
    flag.Parse()

    logger := gologit.New(*debug)
    logger.Debugln("Logging enabled")
    SomeOtherFunc(logger)
}

Documentation

More documentation available at go.pkgdoc.org

License

Released under the MIT license. See LICENSE file for details.