Log4Go Updates: colored text, Printf(), and SetLevelString()

I recently rolled out some updates for my Log4Go package which I'd like to talk about here.

My first update is the most technically appealing one: Printf()-style functionality.

Instead of having to concatenate strings, percent mark placeholders can be used in the same style as fmt.Printf().

Here are some examples:

log4go.Errorf("Expected 4, got: %d", 72)
log4go.Warn("The temperature in %s is %d degrees and rising!", "Saigon", 112)

The second change I made was the most visually appealing: colored text!

The color of the text printed is now dependent on the severity of the message. Errors are red, Warnings are yellow, Info messages are green, Debug messages are cyan, and Trace messages are purple.

Here is a screenshot of how it looks in Mac OS/X:

Credit where credit is due: I used Meng Zhang's excellent Terminal package for the colored text.

My final change makes it easier to set logging levels. The function SetLlevelString() will let you set levels with a case-insensitive string. This is perfect for programs where a log level is passed in as a command line argument.

Here are some samples:


To install the module, feel free to clone the repository or just put the following at the top of your .go files:

import log "github.com/dmuth/google-go-log4go"


Average: 3.6 (13 votes)
Your rating: None