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 logging configuration to the main configuration file #9056

Merged
merged 4 commits into from
Feb 14, 2018

Conversation

jsternberg
Copy link
Contributor

@jsternberg jsternberg commented Nov 3, 2017

Make logfmt the default log output format with json and a more user
friendly console into possible options.

This also adds the ability to suppress the logo output in the configuration
file. If the configuration file fails to be parsed in any way, these options
also fail and the defaults are used.

This change makes it so InfluxDB has a more consistent user output and follows
along with Kapacitor for the default output. That should make it easier to
consolidate Kapacitor and InfluxDB to use the same logging framework and
patterns.

The console logging output can only be used by specifying auto and writing to a TTY. It is not an available log format for logging to a file.

  • Tests pass
  • Rebased/mergable
  • CHANGELOG.md updated
  • Config changes: update sample config (etc/config.sample.toml), server NewDemoConfig method, and Diagnostics methods reporting config settings, if necessary
  • InfluxData Documentation: issue filed or pull request submitted <influxdata/docs.influxdata.com>

@ghost ghost assigned jsternberg Nov 3, 2017
@ghost ghost added the review label Nov 3, 2017
@jsternberg jsternberg force-pushed the js-configure-logging branch 4 times, most recently from 1aafd6c to 88e72a9 Compare November 4, 2017 03:27
@jsternberg jsternberg force-pushed the js-configure-logging branch 6 times, most recently from 8adc0c4 to 4402b51 Compare November 17, 2017 16:56
@jinnatar
Copy link

Would this change also suppress the extra timestamp printed currently? (Hoping that it does.) Or would that become configurable. (Didn't see any clear options for choosing parameters.)

@jsternberg
Copy link
Contributor Author

@Artanicus can you clarify what you mean? Thanks.

Make logfmt the default log output format with json and a more user
friendly console into possible options.
For any systems that want to read the log file in the specific format,
the logo being printed on restart may not be good for those parsers
since the log parser would have to be aware of the logos existance or
capable of just ignoring lines it couldn't parse.

This gives an option to disable the printed logo if required.

Like other logging options, this will fail if the configuration file
itself is invalid.
Copy link
Contributor

@stuartcarnie stuartcarnie left a comment

Choose a reason for hiding this comment

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

Looks good to me.

To clarify, it appears we can expect to receive logfmt from 3rd parties, if they use default settings (auto).

My only nit is that we could receive any of the three formats (JSON, logfmt or console) from a 3rd party and therefore maintaining tools to parse all three will be painful. Given the console format is a little harder to parse (since elements of the data are in different formats), I'd suggest we only allow the console format when it rendering to a tty, limiting what we receive as log files to JSON or logfmt, which already have plenty of tooling.

Copy link
Contributor

@stuartcarnie stuartcarnie left a comment

Choose a reason for hiding this comment

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

After discussion, the only requested change it to prevent console as an option for writing to log files so we don't have to write parsers for a 3rd format.

@jsternberg jsternberg force-pushed the js-configure-logging branch 2 times, most recently from f1a1ad3 to 4f0a6fc Compare February 14, 2018 16:56
This restricts the logging format options so console cannot be chosen.
This way, logs written to a non-TTY will never be the console format.
Copy link
Contributor

@stuartcarnie stuartcarnie left a comment

Choose a reason for hiding this comment

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

LGTM 👍

func (c *Config) New(defaultOutput io.Writer) (*zap.Logger, error) {
w := defaultOutput
format := c.Format
if format == "console" {
Copy link
Contributor

Choose a reason for hiding this comment

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

this will work, but you could also switch this to a white list

if format != "json" && format != "logfmt" && format != "auto" {
    return nil, fmt.Errorf("unknown logging format: %s", format)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error message for most log formats is handled by newEncoder. The reason why this is handled specially is because I didn't want to modify newEncoder to accept auto. Since newEncoder can't make the decision since it doesn't have access to the io.Writer, I wanted to make it explicit that console was specified. Since that means console is a valid input, I had to make it so a user-specified console would be intercepted and would pretend to be an invalid format.

@jsternberg jsternberg merged commit dd21fa1 into master Feb 14, 2018
@jsternberg jsternberg deleted the js-configure-logging branch February 14, 2018 19:39
@ghost ghost removed the review label Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants