Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make caller formatting configurable #319

Closed
skipor opened this issue Feb 19, 2017 · 2 comments
Closed

Make caller formatting configurable #319

skipor opened this issue Feb 19, 2017 · 2 comments

Comments

@skipor
Copy link
Contributor

skipor commented Feb 19, 2017

I have problem like #304, but I want truncate file paths to <parent_folder_name/file_name>. Because of really long my app package path, even truncating to $GOPATH is not enough.
I know that in #201 decided that

Support for mutative external hooks has been deemed "not supported", and won't be coming back.

And, as result, there is no way no modify Entry.Caller via Option
So I found only way to do this: wrap zapcore.Encoder, and truncate Entry.Caller.File before calling wrapped Encoder. But that is really ugly way, and can't be used with beautiful Config helpers.

My best idea how to improve usability in this case is add kind of EncodeCaller into EncoderConfig and use it to encode Caller. Also, this is nice way to solve #304.

Other ways to improve usability:

  • Add modifying hooks, that are called after Core check
    • Not best idea.
  • Allow wrap Encoder easier.
    • Make Config methods exported to add ability for manual Logger build.
skipor added a commit to skipor/zap that referenced this issue Feb 19, 2017
CallerEncoder similar to other encoders for complex types. It allows to configure caller presentation in log.
skipor added a commit to skipor/zap that referenced this issue Feb 20, 2017
CallerEncoder similar to other encoders for complex types. It allows to configure caller presentation in log.
skipor added a commit to skipor/zap that referenced this issue Feb 20, 2017
CallerEncoder similar to other encoders for complex types. It allows to configure caller presentation in log.
@akshayjshah
Copy link
Contributor

Good point - I hadn't thought about making the caller formatting configurable, but it's a good idea. Since you have a PR open, I'll move discussion there.

@akshayjshah akshayjshah changed the title Hard to change how Entry.Caller.File is written to log Make caller formatting configurable (like times and durations) Feb 21, 2017
@akshayjshah akshayjshah changed the title Make caller formatting configurable (like times and durations) Make caller formatting configurable Feb 21, 2017
akshayjshah pushed a commit to skipor/zap that referenced this issue Mar 13, 2017
CallerEncoder similar to other encoders for complex types. It allows to configure caller presentation in log.
akshayjshah pushed a commit to skipor/zap that referenced this issue Mar 14, 2017
CallerEncoder similar to other encoders for complex types. It allows to configure caller presentation in log.
@akshayjshah
Copy link
Contributor

Fixed in #327.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants