github.com/goburrow/gol
go get github.com/goburrow/gol

github.com/goburrow/gol

SLF4J like logging package for Go (golang)

by goburrow

v0.0.0-20161016221943-2d8c917c7cc4 (see all)License:BSD-3-Clause
go get github.com/goburrow/gol
Readme

gol Build Status GoDoc Coverage Status

Simple logging framework for Go applications, inspired by SLF4J.

Introduction

gol (or golog) provides a generic logging API and a simple implementation which supports logging level and hierarchy.

The Logger interface is kept minimal and does not allow you to set level directly but the DefaultLogger, its default implementation, does. You can also create a Logger hierarchy with the DefaultLogger. For example, logger a/b/c will inherit logging level and appender from logger a/b unless its own properties are set.

Example

See example/example.go

package main

import (
    "os"
    "time"

    "github.com/goburrow/gol"
)

var exampleLogger, appLogger gol.Logger

func init() {
    // Get logger with name "app/example"
    exampleLogger = gol.GetLogger("app/example")
    // Logger "app" is the parent of the logger "app/example"
    appLogger = gol.GetLogger("app")
}

func main() {
    exampleLogger.Infof("Running app with arguments: %v.", os.Args)

    exampleLogger.Warnf("Going to do nothing.")
    time.Sleep(1 * time.Second)

    // DefaultLogger is the internal implementation of Logger
    appLogger.(*gol.DefaultLogger).SetLevel(gol.Warn)

    exampleLogger.Infof("You won't see this message.")
    appLogger.Errorf("I %v! %[2]v %[2]v.", "quit", "bye")

    // Output:
    // INFO  [2015-01-14T12:43:35.546+10:00] app/example: Running app with arguments: [/go/bin/example].
    // WARN  [2015-01-14T12:43:35.546+10:00] app/example: Going to do nothing.
    // ERROR [2015-01-14T12:43:36.546+10:00] app: I quit! bye bye.
}

GitHub Stars

12

LAST COMMIT

6yrs ago

MAINTAINERS

0

CONTRIBUTORS

1

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v0.0.0-20161016221943-2d8c917c7cc4
3yrs ago
No alternatives found
No tutorials found
Add a tutorial