Logging chef-client activity to syslog - how?

Hello, I am trying to get chef-client to log to syslog. I am running 10.16.2 and I have found info about this in the JIRA system (http://tickets.opscode.com/browse/CHEF-273)

I installed SyslogLogger and tested it with a simple check script that works just fine:

require 'rubygems’
require 'syslog_logger’
logobj = SyslogLogger.new(“chef-client”)
logobj.info(‘test’)

This is my client.rb:

require 'syslog_logger’
log_level :info
log_location SyslogLogger.new(“chef-client”)
chef_server_url 'http://MYCHEFSERVER:4000
validation_client_name ‘chef-validator’

When I run chef-client I get nothing in syslog, so I tried this client.rb based on a snippet I stumbled across at random (https://gist.github.com/787164)

require 'syslog_logger’
Chef::Log.logger = SyslogLogger.new(“chef-client”)
log_level :info
Chef::Log.logger.info(“Sanity Check”)
log_location STDOUT
chef_server_url 'http://MYCHEFSERVER:4000
validation_client_name ‘chef-validator’

Running chef-client results in “Sanity Check” in my logs, but nothing after that. I suspected a bug like this one (http://tickets.opscode.com/browse/CHEF-1985 ) and instrumented the chef-client source code enough to see that indeed the custom log destination works right up until init() is called in mixlog, but I’m not yet very adept at ruby and didn’t get to the bottom of it this way.

I tried a variety of other syslog gems as well with various combinations and could not find anything that works.

The tickets suggest that logging to syslog is supported, and even that it is the default behavior, but I just can’t get it to work. Can someone point out what I am doing wrong or suggest something to try?

Ooh! this would be perfect if it worked.
I'm currently modifying the chef-client recipe to pipe all output to
/usr/bin/logger. Please post if you get it to work?

On Thu, Dec 20, 2012 at 5:45 PM, Chris Sibbitt
csibbitt@thinkingphones.comwrote:

Hello, I am trying to get chef-client to log to syslog. I am running
10.16.2 and I have found info about this in the JIRA system (
http://tickets.opscode.com/browse/CHEF-273)****


I installed SyslogLogger and tested it with a simple check script that
works just fine: ****


require 'rubygems'****

require 'syslog_logger'****

logobj = SyslogLogger.new("chef-client")****

logobj.info('test')****


This is my client.rb: ****


require 'syslog_logger'****

log_level :info****

log_location SyslogLogger.new("chef-client")****

chef_server_url 'http://MYCHEFSERVER:4000'****

validation_client_name 'chef-validator'****


When I run chef-client I get nothing in syslog, so I tried this client.rb
based on a snippet I stumbled across at random (
client.rb · GitHub) ****


require 'syslog_logger'****

Chef::Log.logger = SyslogLogger.new("chef-client")****

log_level :info****

Chef::Log.logger.info("Sanity Check")****

log_location STDOUT****

chef_server_url 'http://MYCHEFSERVER:4000'****

validation_client_name 'chef-validator'****


Running chef-client results in “Sanity Check” in my logs, but nothing
after that. I suspected a bug like this one (
http://tickets.opscode.com/browse/CHEF-1985 ) and instrumented the
chef-client source code enough to see that indeed the custom log
destination works right up until init() is called in mixlog, but I’m not
yet very adept at ruby and didn’t get to the bottom of it this way.****


I tried a variety of other syslog gems as well with various combinations
and could not find anything that works.****


The tickets suggest that logging to syslog is supported, and even that it
is the default behavior, but I just can’t get it to work. Can someone point
out what I am doing wrong or suggest something to try?****

This is the best I’ve got so far; not much better than piping to logger I’m afraid:

log_location open("| ruby -e “require ‘syslog’; Syslog.open ‘chef-client’; while gets: Syslog.info sub /^.?\[.?\] /, ‘’ end”", ‘w’);

It’s a cheap hack, but it meets my operational requirement so until I have time to rip apart the rest of the logging code it will have to do. The biggest drawback is probably the fact that it maps all logged output to the INFO priority no matter what it was originally.

Would still appreciate help with doing this the “right” way.

From: Jesse Campbell [mailto:hikeit@gmail.com]
Sent: Friday, December 21, 2012 7:40 PM
To: chef
Subject: [chef] Re: Logging chef-client activity to syslog - how?

Ooh! this would be perfect if it worked.
I’m currently modifying the chef-client recipe to pipe all output to /usr/bin/logger. Please post if you get it to work?

On Thu, Dec 20, 2012 at 5:45 PM, Chris Sibbitt <csibbitt@thinkingphones.commailto:csibbitt@thinkingphones.com> wrote:
Hello, I am trying to get chef-client to log to syslog. I am running 10.16.2 and I have found info about this in the JIRA system (http://tickets.opscode.com/browse/CHEF-273)

I installed SyslogLogger and tested it with a simple check script that works just fine:

require 'rubygems’
require 'syslog_logger’
logobj = SyslogLogger.new(“chef-client”)
logobj.infohttp://logobj.info(‘test’)

This is my client.rb:

require 'syslog_logger’
log_level :info
log_location SyslogLogger.new(“chef-client”)
chef_server_url 'http://MYCHEFSERVER:4000
validation_client_name ‘chef-validator’

When I run chef-client I get nothing in syslog, so I tried this client.rb based on a snippet I stumbled across at random (https://gist.github.com/787164)

require 'syslog_logger’
Chef::Log.logger = SyslogLogger.new(“chef-client”)
log_level :info
Chef::Log.logger.infohttp://Log.logger.info(“Sanity Check”)
log_location STDOUT
chef_server_url 'http://MYCHEFSERVER:4000
validation_client_name ‘chef-validator’

Running chef-client results in “Sanity Check” in my logs, but nothing after that. I suspected a bug like this one (http://tickets.opscode.com/browse/CHEF-1985 ) and instrumented the chef-client source code enough to see that indeed the custom log destination works right up until init() is called in mixlog, but I’m not yet very adept at ruby and didn’t get to the bottom of it this way.

I tried a variety of other syslog gems as well with various combinations and could not find anything that works.

The tickets suggest that logging to syslog is supported, and even that it is the default behavior, but I just can’t get it to work. Can someone point out what I am doing wrong or suggest something to try?

chef's config checker requires that whatever object is passed into
log_location either be a file (as specified by a string), or be an object
that responds to the sync= setter.
I have no idea what sync is supposed to do, but at the moment I don't much
care :slight_smile:

With the latest (2.0) version of SyslogLogger, put this in your client.rb
to get it to work:

require 'syslog/logger'
class Syslog::Logger
attr_accessor :sync
end
log_level :info
log_location Syslog::Logger.new("chef-client")

Thanks for pushing me to poke at this, this will clean up a few of my
processes.

On Mon, Dec 24, 2012 at 9:27 AM, Chris Sibbitt
csibbitt@thinkingphones.comwrote:

This is the best I’ve got so far; not much better than piping to logger
I’m afraid:****


log_location open("| ruby -e "require 'syslog'; Syslog.open
'chef-client'; while gets: Syslog.info sub /^.?\[.?\] /, '' end"",
'w');****


It’s a cheap hack, but it meets my operational requirement so until I have
time to rip apart the rest of the logging code it will have to do. The
biggest drawback is probably the fact that it maps all logged output to the
INFO priority no matter what it was originally.****


Would still appreciate help with doing this the “right” way.****


From: Jesse Campbell [mailto:hikeit@gmail.com]
Sent: Friday, December 21, 2012 7:40 PM
To: chef
Subject: [chef] Re: Logging chef-client activity to syslog - how?****


Ooh! this would be perfect if it worked.
I'm currently modifying the chef-client recipe to pipe all output to
/usr/bin/logger. Please post if you get it to work?****


On Thu, Dec 20, 2012 at 5:45 PM, Chris Sibbitt <
csibbitt@thinkingphones.com> wrote:****

Hello, I am trying to get chef-client to log to syslog. I am running
10.16.2 and I have found info about this in the JIRA system (
http://tickets.opscode.com/browse/CHEF-273)****


I installed SyslogLogger and tested it with a simple check script that
works just fine: ****


require 'rubygems'****

require 'syslog_logger'****

logobj = SyslogLogger.new("chef-client")****

logobj.info('test')****


This is my client.rb: ****


require 'syslog_logger'****

log_level :info****

log_location SyslogLogger.new("chef-client")****

chef_server_url 'http://MYCHEFSERVER:4000'****

validation_client_name 'chef-validator'****


When I run chef-client I get nothing in syslog, so I tried this client.rb
based on a snippet I stumbled across at random (
client.rb · GitHub) ****


require 'syslog_logger'****

Chef::Log.logger = SyslogLogger.new("chef-client")****

log_level :info****

Chef::Log.logger.info("Sanity Check")****

log_location STDOUT****

chef_server_url 'http://MYCHEFSERVER:4000'****

validation_client_name 'chef-validator'****


Running chef-client results in “Sanity Check” in my logs, but nothing
after that. I suspected a bug like this one (
http://tickets.opscode.com/browse/CHEF-1985 ) and instrumented the
chef-client source code enough to see that indeed the custom log
destination works right up until init() is called in mixlog, but I’m not
yet very adept at ruby and didn’t get to the bottom of it this way.****


I tried a variety of other syslog gems as well with various combinations
and could not find anything that works.****


The tickets suggest that logging to syslog is supported, and even that it
is the default behavior, but I just can’t get it to work. Can someone point
out what I am doing wrong or suggest something to try?****


I was able to use these attributes to hack the current chef-client
cookbook's config recipe (2.1.4) to do syslogging:

:chef_client => {
:load_gems => {
:SyslogLogger => {
:require_name => "syslog/logger"
}
},
:verbose_logging => "true\nclass Syslog::Logger\nattr_accessor
:sync\ndef initialize\n@level = ::Logger::DEBUG\n@formatter =
Formatter.new\n@@syslog ||=
Syslog.open('chef-client',nil,Syslog::LOG_LOCAL0)\nend\nend\nlog_location
Syslog::Logger.new"
}

On Mon, Dec 24, 2012 at 12:46 PM, Jesse Campbell hikeit@gmail.com wrote:

chef's config checker requires that whatever object is passed into
log_location either be a file (as specified by a string), or be an object
that responds to the sync= setter.
I have no idea what sync is supposed to do, but at the moment I don't much
care :slight_smile:

With the latest (2.0) version of SyslogLogger, put this in your client.rb
to get it to work:

require 'syslog/logger'
class Syslog::Logger
attr_accessor :sync
end
log_level :info
log_location Syslog::Logger.new("chef-client")

Thanks for pushing me to poke at this, this will clean up a few of my
processes.

On Mon, Dec 24, 2012 at 9:27 AM, Chris Sibbitt <
csibbitt@thinkingphones.com> wrote:

This is the best I’ve got so far; not much better than piping to logger
I’m afraid:****


log_location open("| ruby -e "require 'syslog'; Syslog.open
'chef-client'; while gets: Syslog.info sub /^.?\[.?\] /, '' end"",
'w');****


It’s a cheap hack, but it meets my operational requirement so until I
have time to rip apart the rest of the logging code it will have to do. The
biggest drawback is probably the fact that it maps all logged output to the
INFO priority no matter what it was originally.****


Would still appreciate help with doing this the “right” way.****


From: Jesse Campbell [mailto:hikeit@gmail.com]
Sent: Friday, December 21, 2012 7:40 PM
To: chef
Subject: [chef] Re: Logging chef-client activity to syslog - how?****


Ooh! this would be perfect if it worked.
I'm currently modifying the chef-client recipe to pipe all output to
/usr/bin/logger. Please post if you get it to work?****


On Thu, Dec 20, 2012 at 5:45 PM, Chris Sibbitt <
csibbitt@thinkingphones.com> wrote:****

Hello, I am trying to get chef-client to log to syslog. I am running
10.16.2 and I have found info about this in the JIRA system (
http://tickets.opscode.com/browse/CHEF-273)****


I installed SyslogLogger and tested it with a simple check script that
works just fine: ****


require 'rubygems'****

require 'syslog_logger'****

logobj = SyslogLogger.new("chef-client")****

logobj.info('test')****


This is my client.rb: ****


require 'syslog_logger'****

log_level :info****

log_location SyslogLogger.new("chef-client")****

chef_server_url 'http://MYCHEFSERVER:4000'****

validation_client_name 'chef-validator'****


When I run chef-client I get nothing in syslog, so I tried this client.rb
based on a snippet I stumbled across at random (
client.rb · GitHub) ****


require 'syslog_logger'****

Chef::Log.logger = SyslogLogger.new("chef-client")****

log_level :info****

Chef::Log.logger.info("Sanity Check")****

log_location STDOUT****

chef_server_url 'http://MYCHEFSERVER:4000'****

validation_client_name 'chef-validator'****


Running chef-client results in “Sanity Check” in my logs, but nothing
after that. I suspected a bug like this one (
http://tickets.opscode.com/browse/CHEF-1985 ) and instrumented the
chef-client source code enough to see that indeed the custom log
destination works right up until init() is called in mixlog, but I’m not
yet very adept at ruby and didn’t get to the bottom of it this way.****


I tried a variety of other syslog gems as well with various combinations
and could not find anything that works.****


The tickets suggest that logging to syslog is supported, and even that it
is the default behavior, but I just can’t get it to work. Can someone point
out what I am doing wrong or suggest something to try?****


This is great Jesse, thanks for your attention to this!

From: Jesse Campbell [mailto:hikeit@gmail.com]
Sent: Thursday, January 03, 2013 1:29 PM
To: chef
Subject: [chef] Re: RE: Re: Logging chef-client activity to syslog - how?

I was able to use these attributes to hack the current chef-client cookbook’s config recipe (2.1.4) to do syslogging:

:chef_client => {
:load_gems => {
:SyslogLogger => {
:require_name => “syslog/logger”
}
},
:verbose_logging => “true\nclass Syslog::Logger\nattr_accessor :sync\ndef initialize\n@level = ::Logger::DEBUG\n@formatter = Formatter.new\n@@syslog ||= Syslog.open(‘chef-client’,nil,Syslog::LOG_LOCAL0)\nend\nend\nlog_location Syslog::Logger.new”
}

On Mon, Dec 24, 2012 at 12:46 PM, Jesse Campbell <hikeit@gmail.commailto:hikeit@gmail.com> wrote:
chef’s config checker requires that whatever object is passed into log_location either be a file (as specified by a string), or be an object that responds to the sync= setter.
I have no idea what sync is supposed to do, but at the moment I don’t much care :slight_smile:

With the latest (2.0) version of SyslogLogger, put this in your client.rb to get it to work:

require 'syslog/logger’
class Syslog::Logger
attr_accessor :sync
end
log_level :info
log_location Syslog::Logger.new(“chef-client”)
Thanks for pushing me to poke at this, this will clean up a few of my processes.

On Mon, Dec 24, 2012 at 9:27 AM, Chris Sibbitt <csibbitt@thinkingphones.commailto:csibbitt@thinkingphones.com> wrote:
This is the best I’ve got so far; not much better than piping to logger I’m afraid:

log_location open("| ruby -e “require ‘syslog’; Syslog.open ‘chef-client’; while gets: Syslog.info sub /^.?\[.?\] /, ‘’ end”", ‘w’);

It’s a cheap hack, but it meets my operational requirement so until I have time to rip apart the rest of the logging code it will have to do. The biggest drawback is probably the fact that it maps all logged output to the INFO priority no matter what it was originally.

Would still appreciate help with doing this the “right” way.

From: Jesse Campbell [mailto:hikeit@gmail.commailto:hikeit@gmail.com]
Sent: Friday, December 21, 2012 7:40 PM
To: chef
Subject: [chef] Re: Logging chef-client activity to syslog - how?

Ooh! this would be perfect if it worked.
I’m currently modifying the chef-client recipe to pipe all output to /usr/bin/logger. Please post if you get it to work?

On Thu, Dec 20, 2012 at 5:45 PM, Chris Sibbitt <csibbitt@thinkingphones.commailto:csibbitt@thinkingphones.com> wrote:
Hello, I am trying to get chef-client to log to syslog. I am running 10.16.2 and I have found info about this in the JIRA system (http://tickets.opscode.com/browse/CHEF-273)

I installed SyslogLogger and tested it with a simple check script that works just fine:

require 'rubygems’
require 'syslog_logger’
logobj = SyslogLogger.new(“chef-client”)
logobj.infohttp://logobj.info(‘test’)

This is my client.rb:

require 'syslog_logger’
log_level :info
log_location SyslogLogger.new(“chef-client”)
chef_server_url 'http://MYCHEFSERVER:4000
validation_client_name ‘chef-validator’

When I run chef-client I get nothing in syslog, so I tried this client.rb based on a snippet I stumbled across at random (https://gist.github.com/787164)

require 'syslog_logger’
Chef::Log.logger = SyslogLogger.new(“chef-client”)
log_level :info
Chef::Log.logger.infohttp://Log.logger.info(“Sanity Check”)
log_location STDOUT
chef_server_url 'http://MYCHEFSERVER:4000
validation_client_name ‘chef-validator’

Running chef-client results in “Sanity Check” in my logs, but nothing after that. I suspected a bug like this one (http://tickets.opscode.com/browse/CHEF-1985 ) and instrumented the chef-client source code enough to see that indeed the custom log destination works right up until init() is called in mixlog, but I’m not yet very adept at ruby and didn’t get to the bottom of it this way.

I tried a variety of other syslog gems as well with various combinations and could not find anything that works.

The tickets suggest that logging to syslog is supported, and even that it is the default behavior, but I just can’t get it to work. Can someone point out what I am doing wrong or suggest something to try?