summaryrefslogtreecommitdiff
path: root/lib/chef/log
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-05-07 06:58:58 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-05-07 06:58:58 -0700
commit65a8ac5705b7cbe1a9172b9ecdaae38672a395fe (patch)
tree1414c3569b75a3f9570b4d7faac34efc223e3119 /lib/chef/log
parent08b1270498b1555ddfbbafb8d8a9780ebd0b1671 (diff)
downloadchef-65a8ac5705b7cbe1a9172b9ecdaae38672a395fe.tar.gz
Added Windows Event Log logger
Diffstat (limited to 'lib/chef/log')
-rw-r--r--lib/chef/log/winevt.rb100
1 files changed, 100 insertions, 0 deletions
diff --git a/lib/chef/log/winevt.rb b/lib/chef/log/winevt.rb
new file mode 100644
index 0000000000..f138751991
--- /dev/null
+++ b/lib/chef/log/winevt.rb
@@ -0,0 +1,100 @@
+#
+# 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'
+
+if Chef::Platform::windows? and not Chef::Platform::windows_server_2003?
+ if defined? Windows::Constants
+ [:INFINITE, :WAIT_FAILED, :FORMAT_MESSAGE_IGNORE_INSERTS, :ERROR_INSUFFICIENT_BUFFER].each do |c|
+ # These are redefined in 'win32/eventlog'
+ Windows::Constants.send(:remove_const, c) if Windows::Constants.const_defined? c
+ end
+ end
+
+ require 'win32/eventlog'
+end
+
+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
+ FATAL_EVENT_ID = 10103
+
+ # 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 = ::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 fatal(msg)
+ @eventlog.report_event(
+ :event_type => ::Win32::EventLog::ERROR_TYPE,
+ :source => SOURCE,
+ :event_id => FATAL_EVENT_ID,
+ :data => [msg]
+ )
+ end
+
+ end
+ end
+end