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

Chef::Log.info inside a ruby_block does nothing #8725

Open
Lasering opened this issue Jul 9, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@Lasering
Copy link

commented Jul 9, 2019

Description

Using Chef::Log.info inside a ruby_block does nothing. Even if I run with chef-client --log_level debug.

Chef Version

Chef: 14.13.11

Platform Version

CentOS 7

Notes

See https://discourse.chef.io/t/re-re-logging-within-a-ruby-block/6379

@lamont-granquist

This comment has been minimized.

Copy link
Contributor

commented Jul 16, 2019

but it does:

ruby_block "log it" do
  block do
    Chef::Log.info("LOG")
  end
end

results in:

% chef-client -z -j dna.json -c client.rb -l info
[2019-07-16T15:25:13-07:00] INFO: Auto-discovered chef repository at /Users/lamont/zero
[2019-07-16T15:25:13-07:00] INFO: Started Chef Infra Zero at chefzero://localhost:1 with repository at /Users/lamont/zero
  One version per cookbook

Starting Chef Infra Client, version 15.1.14
[2019-07-16T15:25:13-07:00] INFO: *** Chef Infra Client 15.1.14 ***
[2019-07-16T15:25:13-07:00] INFO: Platform: x86_64-darwin16
[2019-07-16T15:25:13-07:00] INFO: Chef-client pid: 4802
[2019-07-16T15:25:18-07:00] INFO: Setting the run_list to ["test::test"] from CLI options
[2019-07-16T15:25:18-07:00] INFO: Run List is [recipe[test::test]]
[2019-07-16T15:25:18-07:00] INFO: Run List expands to [test::test]
[2019-07-16T15:25:18-07:00] INFO: Starting Chef Infra Client Run for coredump.scriptkiddie.lan
[2019-07-16T15:25:18-07:00] INFO: Running start handlers
[2019-07-16T15:25:18-07:00] INFO: Start handlers complete.
resolving cookbooks for run list: ["test::test"]
[2019-07-16T15:25:18-07:00] INFO: Loading cookbooks [test@0.0.1]
Synchronizing Cookbooks:
  - test (0.0.1)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: test::test
  * ruby_block[log it] action run[2019-07-16T15:25:18-07:00] INFO: Processing ruby_block[log it] action run (test::test line 2)
[2019-07-16T15:25:18-07:00] INFO: LOG <=================================== HERE is the log output ==================================
[2019-07-16T15:25:18-07:00] INFO: ruby_block[log it] called

    - execute the ruby block log it
[2019-07-16T15:25:18-07:00] INFO: Chef Infra Client Run complete in 0.068658 seconds

Running handlers:
[2019-07-16T15:25:18-07:00] INFO: Running report handlers
Running handlers complete
[2019-07-16T15:25:18-07:00] INFO: Report handlers complete
Chef Infra Client finished, 1/1 resources updated in 04 seconds
@lamont-granquist

This comment has been minimized.

Copy link
Contributor

commented Jul 16, 2019

easier to see with Chef::Log.warn output:

% chef-client -z -j dna.json -c client.rb
Starting Chef Infra Client, version 15.1.14
resolving cookbooks for run list: ["test::test"]
Synchronizing Cookbooks:
  - test (0.0.1)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: test::test
  * ruby_block[log it] action run[2019-07-16T15:50:23-07:00] WARN: LOG

    - execute the ruby block log it

Running handlers:
Running handlers complete
Chef Infra Client finished, 1/1 resources updated in 05 seconds

the funky looking line is due to: #2931

@Lasering

This comment has been minimized.

Copy link
Author

commented Jul 16, 2019

Maybe because you are using chef-client 15.1.14 and it has been fixed in that later version.

The code I've used to test is more complicated than the one I posted here. Tomorrow I'll add a more complete example.

I'll also test with chef-client 15 to see if that solves it.

@lamont-granquist

This comment has been minimized.

Copy link
Contributor

commented Jul 16, 2019

14.13.11 is the same behavior though:

% chef-client -z -j dna.json -c client.rb
Starting Chef Client, version 14.13.11
resolving cookbooks for run list: ["test::test"]
Synchronizing Cookbooks:
  - test (0.0.1)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: test::test
  * ruby_block[log it] action run[2019-07-16T15:59:52-07:00] WARN: LOG

    - execute the ruby block log it

Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 04 seconds

even if i set the log_location:

% chef-client -z -j dna.json -c client.rb
Starting Chef Client, version 14.13.11
resolving cookbooks for run list: ["test::test"]
Synchronizing Cookbooks:
  - test (0.0.1)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: test::test
  * ruby_block[log it] action run[2019-07-16T16:01:35-07:00] WARN: LOG

    - execute the ruby block log it

Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 04 seconds
@lamont-granquist

This comment has been minimized.

Copy link
Contributor

commented Jul 16, 2019

There's also nothing special about a ruby_block that would affect Chef::Log, so I'm pretty certain that the title has to be inaccurate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.