Hey guys,
I needed to write my own lightweight GO multi-output logger for a work project and I’ve come up with https://github.com/asticode/go-logger.
Basically the projects works like this:
// Create the logger
l, e := logger.NewLogger("myproject", logger.LevelDebug, "%message%")
// Add a stream handler
h, e := logger.NewHandlerStream("")
l.AddHandler("stream", h)
// Add a syslog handler
h, e = logger.NewHandlerSyslog("[%level%]%message%", "syslog_id")
l.AddHandler("syslog", h)
// Add a file handler
h, e = logger.NewHandlerFile("", "/path/to/file")
l.AddHandler("file", h)
// Log a warning message
l.Warning("This is a warning message")
And this will output the message to the specified handlers
I’m not here to advertise at all and I’m rather looking for Gopher’s
opinions (good or bad) on my code and my implementation since I’d like
to know whether I’ve done things right or whether I’ve gone completely
off tracks.
My points of emphasis would be:
- Have I made good use of interfaces?
- Have I made good use of const and global vars ?
- Have I made good use of GO project structure ?
- Have I made good use of GO unit testing package?
- …
I really thank you in advance for the time you’ll put in reviewing my project.
Cheers
Quentin