Coder Social home page Coder Social logo

gol's Introduction

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.
}

gol's People

Contributors

nqv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.