Comments (5)
What does your wrapper do? Can it be achieved by a Handler instead?
from log15.
It provides an adapter from the log4go
API (which takes Sprintf type strings). We're a big project, switching from that to log15. It means the bulk of our code can depend only on our internal log package.
from log15.
Adding a method to the Logger
interface would require a new API version (log15.v3) and I agree it would be a shame if we were to clutter the interface for this reason.
It would probably be OK to add a package scoped variable (guarded by sync/atomic) with an exported log15.SetStackDepth
function to modify it. If the sync/atomic is prohibative we could document that SetStackDepth must be called before any logging is performed.
from log15.
Some parts of our code will use log15 directly (structured logging!), and some through the wrapper (to keep older code working), so a package-level wouldn't work.
Having spent a bit more time with log15, I can do it with a handler like you suggested. The approach is the same as CallerStackHandler
:
func addCaller(r *log15.Record) {
callers := stack.Callers().TrimBelow(stack.Call(r.CallPC[0]))
caller := fmt.Sprintf("%v", callers[0])
if strings.HasPrefix(caller, "nlog.go") { // Trim this package
caller = fmt.Sprintf("%v", callers[1])
}
r.Ctx = append(r.Ctx, "caller", caller)
}
The disadvantage is calling runtime.Callers
again. If Record.CallPC was a 2 array, I could use that. But that's an optimization, and I don't have any numbers, so I should be good for now. Thanks for your help!
from log15.
I'm glad you found a work around.
It's not ready for production yet, but you might want to keep an eye on the log package in https://github.com/go-kit/kit. Its design draws heavily from lessons learned with log15, and I think the way we implemented recording caller information in that package supports the use case you have described here. Disclaimer: I contribute to both log15 and Gokit.
from log15.
Related Issues (20)
- Writing field's address instead of it's value HOT 1
- 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
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.