Introducing Log4Go: Logging for Google Go

When working on my last project, I wanted an easy way to perform logging. I had difficulty finding a logging framework that worked for me, and I figured it would be another good small project if I were to write a log4j-like logger for Google Go.

Here's how to install Log4go:

GOPATH=`pwd` go get # Beginners
go get # Nerds

The latter example assumes that you have the environment variable $GOPATH set. When $GOPATH is set, any packages that are installed will go into a directory hierarchy under that directory. I recommend $HOME/golibs/ as a value for testing and development.

Here's sample usage of Log4go:

import log "github.com/dmuth/google-go-log4go"
    
func main() {
    log.SetLevel(log.DebugLevel)
    log.SetDisplayTime(true)
    log.Info("foobar")
}

And the output might look something like this:

[301.119ms] INFO: foobar

I wrote some sample tests for Log4go. Here's how to run them:

go test ./src/github.com/dmuth/google-go-log4go/

And if the test passes, the output should look like this:

ok      github.com/dmuth/google-go-log4go       0.009s

The source can be downloaded from GitHub:

git clone git://github.com/dmuth/google-go-log4go.git

This project wasn't too terribly complicated, but it gave me some new techniques to try in Google Go. My next project promises to be much more complicated and interesting. Until then, feel free to like, comment, rate, flame or whatever. Smiling

2.4
Average: 2.4 (5 votes)
Your rating: None