Hi there, I have been searching a lot, but I haven't found any logging library that allows me to set different logging levels for different packages. I mean. For example, I want to set my program level to debug, as I develop it, but perhaps, I would also want to a library/package that I use, that of course would use the same logging library, set temporary to debug, to see what happens. Other libraries/packages using the same logging library, should log anything, as I didn't enable them. This is just like Java's log4j or Python's logging work. Of course, the logging library should have multiple types of outputs/appenders, be configurable programatically/from a file, and be thread safe. There are so much logging libraries for golang, but none of them do this...
评论:
recurrency:
dvln:I like
go-kit/log
.The
Logger
-interface is just alternating key values:log.Log(keyvals ... interface{})
.With the
log.With(logger, keyvals ... interface{})
function you can pass in your logger and prepend it with a relevant kv such as level, timestamp, component etc
rauyran:I wrote a package a while back you might want to check out, github.com/dvln/out is the name. It has leveled logging, can manage a couple of writers (screen and log file for instance with independent output level controls, thread safe, and one can flip on log levels based on file name or even routine within a file... although I tend to use those via env control when I want to do that). Regardless, you can modify further as needed...
dazzford:juju's logging package has module level control
If you have a need for those things, then build them or add PRs for those features.
I’m not aware of any lib that has them.
Go is not JAVA and it shouldn’t be.
