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

feature request : interface around time.Now #694

Closed
ran-berenfeld opened this issue Apr 2, 2019 · 1 comment · Fixed by #897
Closed

feature request : interface around time.Now #694

ran-berenfeld opened this issue Apr 2, 2019 · 1 comment · Fixed by #897

Comments

@ran-berenfeld
Copy link

we use some clock testing packages like
https://github.com/jonboulle/clockwork
that relies on the tested code not calling directly time.Now()
can we have some interface in the encoder configuration ?

for example TimeSource interface that implemented the time.Now(), and in the zap encoder configuration an option to put your own interface to supply time ?

@prashantv
Copy link
Collaborator

This may not be exactly what you're looking for, but perhaps it'll solve your problem: There is a testing package in zap which creates a logger that captures logs in-memory: observer.

core, logs := observer.New(zap.ErrorLevel)
logger := zap.New(core)

// pass in logger to code you'r testing

You can use logs.All() to get all logs, with timestamps, or use AllUntimed() to get all logs without timestamps.

abhinav added a commit that referenced this issue Jan 8, 2021
Add WithClock option to control the source of time for logged entries.

Fixes #694

Co-authored-by: Abhinav Gupta <abg@uber.com>
cgxxv pushed a commit to cgxxv/zap that referenced this issue Mar 25, 2022
Add WithClock option to control the source of time for logged entries.

Fixes uber-go#694

Co-authored-by: Abhinav Gupta <abg@uber.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants