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

feat: Add config option for log level #332

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ type GlobalOptions struct {
FilterFiles []string `short:"F" long:"filter-file" description:"Log file(s) to exclude from --file glob. May have multiple values, including multiple globs." yaml:"filter-file,omitempty"`
RenameFields []string `long:"rename_field" description:"Format: 'before=after'. Rename field called 'before' from parsed lines to field name 'after' in Honeycomb events. May have multiple values." yaml:"rename_field,omitempty"`

LogLevel string `long:"log_level" description:"Set the log level. Valid values are 'debug', 'info', 'warn', 'error', 'fatal', 'panic'." default:"info" yaml:"log_level,omitempty"`
Copy link

Choose a reason for hiding this comment

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

Wow, I didn't know logrus supported fatal and panic levels. I wonder if users would find them useful when using honeytail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, probably not. I let Co-Pilot auto generate the comment here 😄

We have log entries for debug, info, error and fatal. We could remove warn and panic as they are unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Coming back to this, I think the comment is valid - panic and warn log levels are valid, we just don't use them at the moment.


Reqs RequiredOptions `group:"Required Options" yaml:"required_options,omitempty"`
Modes OtherModes `group:"Other Modes" yaml:"-"`

Expand Down Expand Up @@ -174,6 +176,13 @@ See https://honeycomb.io/docs/connect/agent/ for more detailed usage instruction

if options.Debug {
logrus.SetLevel(logrus.DebugLevel)
} else if options.LogLevel != "" {
level, err := logrus.ParseLevel(options.LogLevel)
if err != nil {
fmt.Printf("invalid log level: %s\n", options.LogLevel)
os.Exit(1)
}
logrus.SetLevel(level)
}

// Support flag alias: --backfill should cover --backoff --tail.read_from=beginning --tail.stop
Expand Down