chef / chef-apply

The ad-hoc execution tool for the Chef ecosystem.
https://www.chef.sh/
Apache License 2.0
14 stars 14 forks source link

log output is not written to log.location resulting in no output regardless of log.level configured #23

Closed karthanistyr closed 6 years ago

karthanistyr commented 6 years ago

Description

Setting a value to log.level in chef-apply's config file (default: ~/.chef-workstation/config.toml) doesn't affect the logging properly: it only affects a minimal part of the logging.

Chef Apply Version

All versions up until 0.1.13 (latest as of this posting)

Platform Version

Arch Linux patched to latest, as of writing

Replication Case

In .chef-workstation/config.toml:

[log]
level = "debug"

Executing: chef-run myhost path/to/recipe.rb

Client Output

Actual (wrong) output (one line...):

[2018-07-26T22:53:27+08:00] INFO: Initialized logger

Expected output, complete with the chef-client output from the target host: https://gist.github.com/karthanistyr/b007c0225fb44d0ffa8e23cd7d65eed0

Stacktrace

N/A

Superficial analysis

In lib/chef_apply/startup.rb:

def setup_logging
  ChefApply::Log.setup(Config.log.location, Config.log.level.to_sym)
  ChefApply::Log.info("Initialized logger")

  ChefConfig.logger = ChefApply::Log
  # Setting the config isn't enough, we need to ensure the logger is initialized
  # or automatic initialization will still go to stdout
  Chef::Log.init(ChefApply::Log)
  Chef::Log.level = ChefApply::Log.level
end

The ChefApply::Log.level value is reset to warn after the call to Chef::Log.init.

robbkidd commented 6 years ago

You are on a tear, @karthanistyr! Thank you for these bug reports and PRs to solve them. They're in our queue for investigation and review.

robbkidd commented 6 years ago

Confirmed the behavior, but the error lay more in a bug in the log class not initializing the actual output target for writing log entries. The logger was honoring a configured log level, but the log output location was not initialized in a way that the log event output would get written anywhere.

karthanistyr commented 6 years ago

@robbkidd Thank you, I agree with your wording. I may have been fixated with "log level" due to my also filing other issues on that same theme. I do agree this one has to do with log initialisation.