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

Switch to log4rs in the Supervisor #6622

Merged
merged 2 commits into from Jun 13, 2019

Conversation

@christophermaier
Copy link
Contributor

commented Jun 5, 2019

By switching away from env_logger to log4rs, we gain a lot of
configurability, including dynamic configuration changes, allowing
us to selectively toggle log verbosity at runtime.

Out of the box, and without any additional configuration, logging will
behave largely as it does now. We will even honor RUST_LOG
environment variable-based configuration strings as a way to
transition users to the new logging system.

However, by adding a /hab/sup/default/config/log.yml configuration
file (whose format is detailed at
https://docs.rs/log4rs/0.8.3/log4rs/#configuration), users will be
able to greatly influence how logging is done.

A key feature to notice is that if the file contains a refresh_rate
key, then the file will be monitored for changes at runtime. There is
a caveat in the current default implementation, however; if the
Supervisor starts with a configuration file that does not have a
refresh_rate key, then it will never update the active
configuration based on changes to the file. Similarly, if you later
update the file and remove the refresh_rate key, then monitoring
will stop altogether. For now, if you want runtime monitoring, just
always have a refresh_rate present. We can change this in the
future, though; follow #6588 for details.

A basic, refreshing configuration file would look like this:

refresh_rate: 5 seconds

appenders:
  stdout:
    kind: console
    encoder:
      pattern: "[{d(%Y-%m-%dT%H:%M:%SZ)(utc)} {l} {module}] {message}{n}"

root:
  level: error
  appenders:
    - stdout

To selectively filter on modules, add some loggers to that, like so:

loggers:
  tokio_threadpool:
    level: trace
  habitat_sup::manager::service_updater:
    level: debug

Be sure to read the code comments for further details.

Fixes #6500
Fixes #6583

Signed-off-by: Christopher Maier cmaier@chef.io

@chef-expeditor

This comment has been minimized.

Copy link

commented Jun 5, 2019

Hello christophermaier! Thanks for the pull request!

Here is what will happen next:

  1. Your PR will be reviewed by the maintainers.
  2. If everything looks good, one of them will approve it, and your PR will be merged.

Thank you for contributing!

@baumanj
Copy link
Member

left a comment

Just some tiny tweaks

components/sup/src/logger.rs Outdated Show resolved Hide resolved

@christophermaier christophermaier force-pushed the cm/dynamic-logging branch 2 times, most recently from a46cdbf to d56241d Jun 7, 2019

@baumanj

baumanj approved these changes Jun 7, 2019

@baumanj baumanj force-pushed the cm/dynamic-logging branch from d56241d to b5b6d88 Jun 10, 2019

@baumanj baumanj force-pushed the cm/dynamic-logging branch 2 times, most recently from 841fcb5 to d05b493 Jun 11, 2019

christophermaier and others added some commits May 21, 2019

Switch to log4rs in the Supervisor
By switching away from `env_logger` to `log4rs`, we gain a lot of
configurability, including _dynamic_ configuration changes, allowing
us to selectively toggle log verbosity at runtime.

Out of the box, and without any additional configuration, logging will
behave largely as it does now. We will even honor `RUST_LOG`
environment variable-based configuration strings as a way to
transition users to the new logging system.

However, by adding a `/hab/sup/default/config/log.yml` configuration
file (whose format is detailed at
https://docs.rs/log4rs/0.8.3/log4rs/#configuration), users will be
able to greatly influence how logging is done.

A key feature to notice is that if the file contains a `refresh_rate`
key, then the file will be monitored for changes at runtime. There is
a caveat in the current default implementation, however; if the
Supervisor starts with a configuration file that does _not_ have a
`refresh_rate` key, then it will _never_ update the active
configuration based on changes to the file. Similarly, if you later
update the file and _remove_ the `refresh_rate` key, then monitoring
will _stop_ altogether. For now, if you want runtime monitoring, just
always have a `refresh_rate` present. We can change this in the
future, though; follow #6588 for details.

A basic, refreshing configuration file would look like this:

```yaml
refresh_rate: 5 seconds

appenders:
  stdout:
    kind: console
    encoder:
      pattern: "[{d(%Y-%m-%dT%H:%M:%SZ)(utc)} {l} {module}] {message}{n}"

root:
  level: error
  appenders:
    - stdout
```

To selectively filter on modules, add some `loggers` to that, like so:

```yaml
loggers:
  tokio_threadpool:
    level: trace
  habitat_sup::manager::service_updater:
    level: debug
```

Be sure to read the code comments for further details.

Fixes #6500
Fixes #6583

Signed-off-by: Christopher Maier <cmaier@chef.io>
Rebase fixups
Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>

@baumanj baumanj force-pushed the cm/dynamic-logging branch from d05b493 to e4b598d Jun 11, 2019

@baumanj baumanj merged commit 6dfd1c2 into master Jun 13, 2019

5 checks passed

DCO This commit has a DCO Signed-off-by
Details
buildkite/habitat-sh-habitat-master-verify Build #2281 passed (2 hours, 1 minute, 33 seconds)
Details
buildkite/habitat-sh-habitat-master-website Build #2584 passed (2 minutes, 15 seconds)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
expeditor/config-validation Validated your Expeditor config file
Details

@baumanj baumanj deleted the cm/dynamic-logging branch Jun 13, 2019

chef-ci added a commit that referenced this pull request Jun 13, 2019

Update CHANGELOG.md with details from pull request #6622
Obvious fix; these changes are the result of automation not creative thinking.

christophermaier added a commit that referenced this pull request Jun 28, 2019

Document logging configuration for the Supervisor
This really should have been included in #6622.

Signed-off-by: Christopher Maier <cmaier@chef.io>

christophermaier added a commit that referenced this pull request Jun 28, 2019

Document logging configuration for the Supervisor
This really should have been included in #6622.

Signed-off-by: Christopher Maier <cmaier@chef.io>

christophermaier added a commit that referenced this pull request Jul 1, 2019

Document logging configuration for the Supervisor
This really should have been included in #6622.

Signed-off-by: Christopher Maier <cmaier@chef.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.