https://github.com/dmuth/google-go-log4go
A log4j analogue for GoLang.
https://github.com/dmuth/google-go-log4go
Last synced: 3 months ago
JSON representation
A log4j analogue for GoLang.
- Host: GitHub
- URL: https://github.com/dmuth/google-go-log4go
- Owner: dmuth
- License: other
- Created: 2013-05-16T02:57:09.000Z (about 13 years ago)
- Default Branch: main
- Last Pushed: 2020-09-03T22:21:47.000Z (almost 6 years ago)
- Last Synced: 2025-04-12T14:51:29.596Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 105 KB
- Stars: 7
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Introducing Log4go
Still being new to Google Go, I wanted a logging facility. I didn't
have much luck finding one, so I decided to write a quick and dirty
implementation of Log4j.
### Installation
Installation is easy. First make sure you have your [GOPATH](http://golang.org/doc/code.html#GOPATH) setup properly. Then use `go get` to download and compile this package.
go get github.com/dmuth/google-go-log4go
Also, make sure your $GOPATH environment variable is set up properly: `export GOPATH=$HOME/golib` or similar
### Usage
import log "github.com/dmuth/google-go-log4go"
func main() {
log.SetLevel(log.DebugLevel)
log.SetDisplayTime(true)
log.Info("foobar")
//
// Strings work, too.
//
log.SetLevelString("info")
log.Info("baz")
//
// Strings are even case-insensitive!
//
log.SetLevelString("INFO")
log.Info("blurfl")
//
// I herd u liek Printf()
//
log.Infof("Number of widgets: %d", 1001)
}
And you can expect to see output like this:

(Colored text is created with to Meng Zhang's excellent Terminal package: https://github.com/wsxiaoys/terminal)
### Escaping malicious input
It was pointed out to me that if things like invalid logins, SQL
injection attempts, etc. are logged, an would-be attacker could pass in
the backspace character (ASCII 8) to "hide" output on a casual glance.
This package tries to protect against that by escaping anything with an
ASCII value of less than 32. This includes carriage returns (ASCII 13)
and newlines (ASCII 10).
Here is an example of an attacker trying to use backspaces, and what
this module would print out instead:
ERROR: Failed login: BlackHat[0x08][0x08][0x08][0x08][0x08][0x08][0x08][0x08]WhiteHat
### Testing
`go test ./src/github.com/dmuth/google-go-log4go/`
You should see output like this:
`ok github.com/dmuth/google-go-log4go 0.009s`
### Contact Me
This is my first ever Google Go package. Chances are that I've done like over 9,000 things the wrong way. Please drop me a line if you liked the package, thought it sucked, want to discuss the merits of velociraptors as housepets, or whatever.
My email address is doug.muth@gmail.com. Additional contact methods can be found at http://www.dmuth.org/contact Thanks!