Comments (6)
That sounds like a great feature.
I like the idea of thinking of this as the argument beeing a prefix, eg. "".
The level logic would not set all loggers beneath it to a level but the
opposite; when fetching the level, stop when a defined level is found,
splitting the module name by '/'.
from go-logging.
@op sgtm. In that case, I suggest prefixing everything with /
. Many systems make the mistake of removing the leading slash (favoring things like "foo/bar", "foo/bar/baz"
), but pathing systems have the leading /
for good reasons, like namespacing/mounting.
Extending this analogy, i could totally see this making sense:
log1 := logging.MustGetLogger("/")
log2 := logging.MustGetLogger("/foo")
log3 := logging.MustGetLogger("/foo/bar")
logging.SetLevel(logging.ERROR, "/foo") // log2 and log2 are now at logging.ERROR
Or:
log1 := logging.RootLogger() // has prefix of "/"
log2 := logging.NewLogger(log1, "foo") // has prefix /foo
log3 := logging.NewLogger(log2, "bar") // has prefix /foo/bar
logging.SetLevel(logging.ERROR, "/foo") // log2 and log2 are now at logging.ERROR
Logger Tree
Note that up there I'm constructing loggers explicitly, whereas you prefer static loggers (GetLogger
). It's your module and probably should think thrice before breaking the interface, but I think constructing Loggers explicitly makes sense. This is particularly apparent when instantiating objects in a module twice, and wanting to redirect their logging separately.
I think go-logging could work phenomenally well with a logger-tree model similar to how google's context
module works. If you haven't seen it, check it out. it's really a great piece of interface design. http://godoc.org/code.google.com/p/go.net/context
from go-logging.
@jbenet That's worth a thought. Why do you want to have relative paths for loggers though? I believe that might lead to code that is harder to reason about. Very flexible, I agree.
I've been thinking of going the opposite route. Somehow, make it possible to just say logging.New()
, and have that automatically figure out the package path and re-use that.
Keep the ideas coming. :)
from go-logging.
Why do you want to have relative paths for loggers though? I believe that might lead to code that is harder to reason about. Very flexible, I agree.
On the contrary. Static initialziation is very hard to reason about / deal with when changing the package structure or instantiation of things. I'd follow the context
example.
logging.New()
, and have that automatically figure out the package path and re-use that.
seems too magic to me. sometimes i don't care about logging per package, but --say-- per incoming request. (useful to change logging level on specific requests across packages)
from go-logging.
One more reason. being able to do this (on a per-request, or whatever, basis):
log := logger.WithPrefix("[Peer: %s] ", local.peer.ID())
log.Debug("trying to do something with %s and %s, with %s", thisThing, thatThing, anotherPeer.ID())
// [Peer: abcbacbacbbacbabc] trying to do something with aaaaa and bbbbb, with dfdffdfdfdffdfdfdfd
log.Error("something bad happened: %s", err)
// [Peer: abcbacbacbbacbabc] something bad happened: all the things broke.
Instead of, everywhere:
log.Debug("[Peer: %s] trying to do something with %s and %s, with %s", local.peer.ID(), thisThing, thatThing, anotherPeer.ID())
// [Peer: abcbacbacbbacbabc] trying to do something with aaaaa and bbbbb, with dfdffdfdfdffdfdfdfd
log.Error("[Peer: %s] something bad happened: %s", local.peer.ID(), err)
// [Peer: abcbacbacbbacbabc] something bad happened: all the things broke.
from go-logging.
Instead of "WithPrefix", I would check the design of structlog and go that way:
log := log.Bind("Peer", local.peer.ID())
log = log.Bind("Other", foobar)
log.Debug("doing something")
so basically store a map[string]interface{}
and dump that as a prefix. You need a value semantic for return values, but it's more powerful because you can even overwrite an object by simply rebinding it. Moreover, it opens the door to having a json.formatter to dump logs in a machine-parsable format.
from go-logging.
Related Issues (20)
- change delimiter in output format
- Logger registry singleton
- Duplicate print in log HOT 3
- *Logger type uses global backend in IsEnabledFor method
- log rotate functionality HOT 1
- build fails on raspberry pi 3 running debian stretch HOT 1
- Diffrent format / config for diffrent level HOT 1
- Set Logging Level HOT 5
- Add mqttlog backend to README
- Getting formatted logs in file and on cmd HOT 1
- go1.12 and too many arguments HOT 1
- Test failure: TestLogCallpath incorrect callpath HOT 2
- Disable logging HOT 1
- Rotating files HOT 1
- How to customize the request id? HOT 1
- Add a standard logger
- Question: Can you set maximum logging level HOT 1
- How to turn off line numbers in production env? HOT 1
- How do I set up multiple log files?
- [Question] How to log to a file? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-logging.