A simple wrapper for Go "log" that provides toggle-able debug support.
NOTE: gologit is currently deprecated. Check out mlog instead.
$ go get github.com/cactus/gologit
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)
}
More documentation available at go.pkgdoc.org
Released under the MIT license. See LICENSE
file for details.