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

Add InferLevelsWithTimestamp option #101

Merged
merged 2 commits into from
Dec 18, 2021
Merged

Conversation

lgfa29
Copy link
Contributor

@lgfa29 lgfa29 commented Oct 28, 2021

This PR adds a new option called InferLevelsWithTimestamp to the StandardLoggerOptions that allow ignoring timestamps from the beginning of log lines before attempting to infer log level.

Timestamp detection is done using a simple regular expression that looks for characters commonly found in timetamps, such as digits, :, / etc.

A new option was added to avoid modifying the existing InferLevels options. An alternative approach that I thought about was to add a InferLevelsOptions attribute to control how infer levels work that could a new struct or a bit mask:

// As bit flags
appLogger.StandardWriter(&hclog.StandardLoggerOptions{
  InferLevels: true,
  InferLevelsOptions: hclog.IgnoreTimestamps
})

// As struct
appLogger.StandardWriter(&hclog.StandardLoggerOptions{
  InferLevels: true,
  InferLevelsOptions: &hclog.InferLevelsOptions{
    IgnoreTimestamps: true,
  }
})

But I'm not sure if this approach is better, so I'm open for feedback 🙂

Closes #100

@lgfa29 lgfa29 requested a review from evanphx October 28, 2021 22:10
stdlog.go Outdated Show resolved Hide resolved
@lgfa29 lgfa29 requested a review from evanphx December 6, 2021 23:18
@evanphx evanphx merged commit 37db868 into master Dec 18, 2021
@evanphx evanphx deleted the infer-level-with-timestamp branch December 18, 2021 00:01
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.

log.SetFlags(0) doesn't remove timestamp from log lines, preventing InferLevels to work properly
2 participants