Skip to content

Comments

Add ExcludeKey option to TextFormatter#1433

Open
ningyougang wants to merge 1 commit intosirupsen:masterfrom
ningyougang:add-exclude-key-option
Open

Add ExcludeKey option to TextFormatter#1433
ningyougang wants to merge 1 commit intosirupsen:masterfrom
ningyougang:add-exclude-key-option

Conversation

@ningyougang
Copy link

@ningyougang ningyougang commented May 15, 2024

  • Add ExcludeKey option to TextFormatter
  • AS-IS (ExcludeKey : false, this is default)

    time="2024-05-14T16:47:03+09:00" level=warning msg="message"
    
  • TO-BE (after applied ExcludeKey : true)

    2024-05-14T16:47:03+09:00 warning message
    

I think this is a common case, when some log collector agent collect the logs from file or standard output, does not need the startingKey(e.g. time=)

@ningyougang ningyougang force-pushed the add-exclude-key-option branch from cd432c8 to aedfb7c Compare May 15, 2024 00:27

if !f.needsQuoting(stringVal) {
// write value without quoting directly when ExcludeKey is true
if f.ExcludeKey {
Copy link
Author

Choose a reason for hiding this comment

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

If configure ExcludeKey as true, just write value without quoting directly, otherwise, the logs will be as below

"0001-01-01T00:00:00Z" warning "message"

@ningyougang ningyougang force-pushed the add-exclude-key-option branch from aedfb7c to a886e5b Compare May 15, 2024 00:31
b.WriteString(stringVal)
} else {
b.WriteString(fmt.Sprintf("%q", stringVal))
}
Copy link
Author

Choose a reason for hiding this comment

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

Keep the same logic as before when ExcludeKey is false(this is default)

@ningyougang
Copy link
Author

Can someone review this PR?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants