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

Added zapcore.TimeEncoderOfLayout #629

Merged
merged 11 commits into from
Jul 7, 2020
Merged

Conversation

tmshn
Copy link
Contributor

@tmshn tmshn commented Aug 31, 2018

I added zapcore.TimeEncoderOfFormat to make it easy to build TimeEncoder of custom format.

You can use it in code:

config := zap.NewDevelopmentConfig()
config.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout("06/01/02 03:04pm")

or, with JSON:

{
  "encoderConfig": {
    "timeEncoder": {
       "layout": "06/01/02 03:04pm"
     }
  }
}

or, with YAML:

encoderConfig:
  timeEncoder:
    layout: '06/01/02 03:04pm'

@CLAassistant
Copy link

CLAassistant commented Aug 31, 2018

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Aug 31, 2018

Codecov Report

Merging #629 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #629      +/-   ##
==========================================
+ Coverage   98.33%   98.35%   +0.01%     
==========================================
  Files          43       43              
  Lines        2349     2366      +17     
==========================================
+ Hits         2310     2327      +17     
  Misses         32       32              
  Partials        7        7              
Impacted Files Coverage Δ
zapcore/encoder.go 88.23% <100.00%> (+1.96%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39aa3a1...c6de7e9. Read the comment docs.

Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the best format to pass arguments, but I like the general idea.

Thoughts @abhinav?

zapcore/encoder.go Show resolved Hide resolved
zapcore/encoder.go Outdated Show resolved Hide resolved
@tmshn
Copy link
Contributor Author

tmshn commented Jun 18, 2020

Actually I'm wondering which word to use, "format" or "layout"...

zapcore/encoder.go Outdated Show resolved Hide resolved
@prashantv
Copy link
Collaborator

Actually I'm wondering which word to use, "format" or "layout"...

Good question, since Go tends to use the word layout for the argument, it makes sense to use that in the YAML config.

@tmshn
Copy link
Contributor Author

tmshn commented Jun 20, 2020

Don't know why codecov fails...

Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good, thanks @tmshn!

zapcore/encoder.go Show resolved Hide resolved
Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good, @abhinav does this look OK to you as well?

zapcore/encoder_test.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@abhinav abhinav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM besides minor comments. Thanks!

zapcore/encoder.go Outdated Show resolved Hide resolved
zapcore/encoder_test.go Outdated Show resolved Hide resolved
zapcore/encoder_test.go Outdated Show resolved Hide resolved
tmshn and others added 3 commits June 24, 2020 11:24
@prashantv prashantv changed the title Added zapcore.TimeEncoderOfFormat Added zapcore.TimeEncoderOfLayout Jul 7, 2020
@prashantv prashantv merged commit 275c926 into uber-go:master Jul 7, 2020
@tmshn tmshn deleted the format-encoder branch July 8, 2020 02:15
cgxxv pushed a commit to cgxxv/zap that referenced this pull request Mar 25, 2022
I added `zapcore.TimeEncoderOfFormat` to make it easy to build `TimeEncoder` of custom format.

You can use it in code:

```go
config := zap.NewDevelopmentConfig()
config.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout("06/01/02 03:04pm")
```

or, with JSON:

```json
{
  "encoderConfig": {
    "timeEncoder": {
       "layout": "06/01/02 03:04pm"
     }
  }
}
```

or, with YAML:
```yaml
encoderConfig:
  timeEncoder:
    layout: '06/01/02 03:04pm'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants