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

Configure a custom zap logger #102

Closed
moul opened this issue Sep 3, 2020 · 7 comments
Closed

Configure a custom zap logger #102

moul opened this issue Sep 3, 2020 · 7 comments
Labels
effort/hours Estimated to take one or several hours exp/novice Someone with a little familiarity can pick up kind/enhancement A net-new feature or improvement to an existing feature status/ready Ready to be worked

Comments

@moul
Copy link
Member

moul commented Sep 3, 2020

Hi,

We (@berty) are using zap extensively and improving our logging experience; we initialize our zap logger in a custom way:

Our current integration with ipfs/go-log is bad: https://github.com/berty/berty/blob/295bef9a6cced69feebf7b5e16525a112e74cdf8/go/cmd/berty/opts.go#L235-L254


I can open a PR against your repo to add new helpers, but I need to know if you accept changing the current API of your package and what kind of change you prefer

What about adding a new SetZapLogger(*zap.Logger) function, that I would use like this:

ipfs_log.SetZapLogger(myLogger.Named("ipfs"))

Another solution is to accept custom Options so we can pass a WrapCore(customCore) that go-log can chain in the New or within a WithOption.

What do you think? any better idea?

@moul moul added the need/triage Needs initial labeling and prioritization label Sep 3, 2020
@welcome
Copy link

welcome bot commented Sep 3, 2020

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

@jacobheun
Copy link

@lanzafame do you have any thoughts on this request/suggestion?

@jacobheun jacobheun added the need/maintainers-input Needs input from the current maintainer(s) label Sep 25, 2020
@BigLep
Copy link

BigLep commented Mar 29, 2021

@aschmahmann : are able to provide input on this?

@lanzafame
Copy link
Contributor

@moul sorry, for the slow reply, I have been on paternity leave.

I am open to the addition of the SetZapLogger function.

@aschmahmann aschmahmann added status/ready Ready to be worked kind/enhancement A net-new feature or improvement to an existing feature exp/novice Someone with a little familiarity can pick up effort/hours Estimated to take one or several hours and removed need/maintainers-input Needs input from the current maintainer(s) need/triage Needs initial labeling and prioritization labels Apr 12, 2021
@aschmahmann aschmahmann removed their assignment Apr 12, 2021
@MDobak
Copy link
Contributor

MDobak commented May 30, 2021

I wanted to do a PR for this issue, but from what I can see, it looks a bit more complicated. If I understand correctly, the proposed SetZapLogger method would only replace already created loggers from the loggers map. The problem is, that any logger created later by the Logger function would not use the new logger.

What do you think about adding a SetPrimaryCore function instead that could look like this:

func SetPrimaryCore(core zapcore.Core) {
	loggerMutex.Lock()
	defer loggerMutex.Unlock()

	if primaryCore != nil {
		loggerCore.ReplaceCore(primaryCore, core)
	} else {
		loggerCore.AddCore(core)
	}
	primaryCore = core
}

?

@lanzafame
Copy link
Contributor

@MDobak The fix to this needs to both replace the existing and make sure that any new loggers use the provided zapcore.Core. Otherwise loggers that are created in dependencies will operate differently to loggers created in the application. The PR you created looks good except the missing functionality of updating existing loggers.

@MDobak
Copy link
Contributor

MDobak commented Jun 3, 2021

@lanzafame The SetPrimaryCore function sets/replaces the core in the lockedMultiCore structure that is used by all loggers, effectively updating all existing loggers and any that will be created later. I've updated the test in my PR to cover this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/hours Estimated to take one or several hours exp/novice Someone with a little familiarity can pick up kind/enhancement A net-new feature or improvement to an existing feature status/ready Ready to be worked
Projects
None yet
Development

No branches or pull requests

7 participants