diff options
Diffstat (limited to 'lib/chef/log')
-rw-r--r-- | lib/chef/log/syslog.rb | 46 | ||||
-rw-r--r-- | lib/chef/log/winevt.rb | 99 |
2 files changed, 145 insertions, 0 deletions
diff --git a/lib/chef/log/syslog.rb b/lib/chef/log/syslog.rb new file mode 100644 index 0000000000..0c8190797f --- /dev/null +++ b/lib/chef/log/syslog.rb @@ -0,0 +1,46 @@ +# +# Author:: Lamont Granquist (<lamont@chef.io>) +# Author:: SAWANOBORI Yukihiko (<sawanoboriyu@higanworks.com>) +# Copyright:: Copyright (c) 2015 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'logger' +require 'syslog-logger' +require 'chef/mixin/unformatter' + +class Chef + class Log + # + # Chef::Log::Syslog class. + # usage in client.rb: + # log_location Chef::Log::Syslog.new("chef-client", ::Syslog::LOG_DAEMON) + # + class Syslog < Logger::Syslog + include Chef::Mixin::Unformatter + + attr_accessor :sync, :formatter + + def initialize(program_name = 'chef-client', facility = ::Syslog::LOG_DAEMON, logopts=nil) + super + return if defined? ::Logger::Syslog::SYSLOG + ::Logger::Syslog.const_set :SYSLOG, SYSLOG + end + + def close + end + end + end +end + diff --git a/lib/chef/log/winevt.rb b/lib/chef/log/winevt.rb new file mode 100644 index 0000000000..c5b7c3485a --- /dev/null +++ b/lib/chef/log/winevt.rb @@ -0,0 +1,99 @@ +# +# Author:: Jay Mundrawala (<jdm@chef.io>) +# +# Copyright:: 2015, Chef Software, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/event_loggers/base' +require 'chef/platform/query_helpers' +require 'chef/mixin/unformatter' + +class Chef + class Log + # + # Chef::Log::WinEvt class. + # usage in client.rb: + # log_location Chef::Log::WinEvt.new + # + class WinEvt + # These must match those that are defined in the manifest file + INFO_EVENT_ID = 10100 + WARN_EVENT_ID = 10101 + DEBUG_EVENT_ID = 10102 + ERROR_EVENT_ID = 10103 + FATAL_EVENT_ID = 10104 + + # Since we must install the event logger, this is not really configurable + SOURCE = 'Chef' + + include Chef::Mixin::Unformatter + + attr_accessor :sync, :formatter, :level + + def initialize(eventlog=nil) + @eventlog = eventlog || ::Win32::EventLog::open('Application') + end + + def close + end + + def info(msg) + @eventlog.report_event( + :event_type => ::Win32::EventLog::INFO_TYPE, + :source => SOURCE, + :event_id => INFO_EVENT_ID, + :data => [msg] + ) + end + + def warn(msg) + @eventlog.report_event( + :event_type => ::Win32::EventLog::WARN_TYPE, + :source => SOURCE, + :event_id => WARN_EVENT_ID, + :data => [msg] + ) + end + + def debug(msg) + @eventlog.report_event( + :event_type => ::Win32::EventLog::INFO_TYPE, + :source => SOURCE, + :event_id => DEBUG_EVENT_ID, + :data => [msg] + ) + end + + def error(msg) + @eventlog.report_event( + :event_type => ::Win32::EventLog::ERROR_TYPE, + :source => SOURCE, + :event_id => ERROR_EVENT_ID, + :data => [msg] + ) + end + + def fatal(msg) + @eventlog.report_event( + :event_type => ::Win32::EventLog::ERROR_TYPE, + :source => SOURCE, + :event_id => FATAL_EVENT_ID, + :data => [msg] + ) + end + + end + end +end |