Last active
February 12, 2016 15:07
-
-
Save inokappa/032d2ef1cdb5ba5f7ebb to your computer and use it in GitHub Desktop.
Ruby スクリプトから Windows Server のイベントログにログを送るメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'win32/eventlog' | |
class EventLog | |
def initialize() | |
@logger = Win32::EventLog.new | |
@app_source = "oreno-app" | |
end | |
def info(event_id, message) | |
puts message | |
@logger.report_event( | |
:source => @app_source, | |
:event_type => Win32::EventLog::INFO_TYPE, | |
:event_id => event_id, | |
:data => message | |
) | |
end | |
def warn(event_id, message) | |
puts message | |
@logger.report_event( | |
:source => @app_source, | |
:event_type => Win32::EventLog::WARN_TYPE, | |
:event_id => event_id, | |
:data => message | |
) | |
end | |
def crit(event_id, message) | |
puts message | |
@logger.report_event( | |
:source => @app_source, | |
:event_type => Win32::EventLog::ERROR_TYPE, | |
:event_id => event_id, | |
:data => message | |
) | |
end | |
end | |
class OrenoSvc | |
def main() | |
eventlog = EventLog.new() | |
eventlog.info(65500, "Starting Oreno Service ...") | |
trap "SIGINT" do | |
eventlog.warn(65501, "stop signal was received : Stopping loop ...") | |
exit 0 | |
end | |
while true | |
sleep(60) | |
eventlog.info(65500, "Komanechi!! at " + Time.now.strftime("%Y/%m/%d %H:%M:%S ")) | |
end | |
end | |
end | |
ore = OrenoSvc.new() | |
ore.main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment