Comments (10)
https://github.com/inconshreveable/log15/blob/master/ext/handler.go
The EscalateErrHandler
might be one way to deal with error
types.
from log15.
You basically don't ever want to format values into your log messages, because then your data is no longer structured and can't be easily parsed by a machine. Instead prefer:
log.Info("some text", "max", max, "min", min, "someCtx", 42)
For errors, my own code uses 'err', usually like this:
f, err := os.Open(path)
log.Debug("open output file", "path", path, "err", err)
if err != nil {
// handle error
}
I have considered allowing syntax to format the context keys into the message as well for additional human readability, but I haven't found I really needed it:
log.Debug("open %(path)s", "path" path, "err", err)
from log15.
Ok, good to know. "err" is a bit shorter than "error" indeed. Guess I'll use that. Thanks!
from log15.
Just found out that the context of child loggers doesn't override the content of a parent (because it's a slice, I just saw in the implementation). Should I re-create the necessary context each time?
from log15.
It appends to the context (or should at least) so:
l := log.New("foo", 1)
l2 := l.New("bar", 2)
l2.Info("test") // prints msg=test foo=1 bar=2
If you want a logger with less or no context, use the appropriate parent or the root logger, which always has no context. Does that make sense?
from log15.
Yes, my use case was this:
log := l.New("mod", "watcher", "fn", "main", "instance", 908632)
startSomeModule(log.New())
In this way, startSomeModule
would override mod
and fn
everytime (by creating new subloggers, I hope this is not a very heavyweight operation to do on every function call), but the instance
context variable would be kept (not overridden).
In any case, it's no big deal, I'll work around it.
from log15.
You want to create a new logger with the appropriate context whenever it becomes relevant, so for your use case:
logger := log.New("instance", 908632)
startSomeModule(logger.New("mod", watcherValue, "fn", fnName))
You could just pass the logger into startSomeModule and have it create the child logger there as well.
from log15.
You could just pass the logger into startSomeModule and have it create the child logger there as well.
That's what startSomeModule
does, in fact. Like I said, it's a small change so no big deal :).
from log15.
awesome! closing this out
from log15.
Thanks for all the help!
from log15.
Related Issues (20)
- Add Illumos support HOT 1
- support log rotate HOT 3
- Expose the runtime.Callers skip HOT 1
- tag a new release HOT 1
- v2.12 Build Issues HOT 3
- Support for a kv-generating interface on log arguments
- Normal log15.Root() not colorized on Cygwin
- logfmt/json keys for msg/lvl/t are hard-coded HOT 3
- Allow logging in UTC HOT 2
- Use Semantic Version Tags compatible with the new Go modules HOT 1
- Please add a go.mod file HOT 1
- make NetHandler able to log to an URL?
- No way to close files opened when a new FileHandler is created.
- Default Lvl is LvlCrit HOT 1
- proposal: add Fatal() HOT 1
- Test failure while building v2.15
- Use semantic versioning to satisfy `go mod`
- Is this library maintained? HOT 3
- CallerFileHandler should include package name
- Different outputs for different functions
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 log15.