diff options
author | 2012-10-26 13:00:04 +0200 | |
---|---|---|
committer | 2012-10-26 13:00:04 +0200 | |
commit | 7670cccf083e25676804c503582091a3eadb00cf (patch) | |
tree | 8aa8d9a6a760e2aa10c3d2f30df315f34c70ffc7 /lib/gorg/log.rb | |
parent | Initial commit (diff) | |
download | gorg-7670cccf083e25676804c503582091a3eadb00cf.tar.gz gorg-7670cccf083e25676804c503582091a3eadb00cf.tar.bz2 gorg-7670cccf083e25676804c503582091a3eadb00cf.zip |
Import distributed 0.6.4 release.0.6.4
Diffstat (limited to 'lib/gorg/log.rb')
-rw-r--r-- | lib/gorg/log.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/gorg/log.rb b/lib/gorg/log.rb new file mode 100644 index 0000000..4ef05d6 --- /dev/null +++ b/lib/gorg/log.rb @@ -0,0 +1,56 @@ +### Copyright 2004, Xavier Neys (neysx@gentoo.org) +# # +# # This file is part of gorg. +# # +# # gorg is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # gorg is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# # GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with gorg; if not, write to the Free Software +### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# Write logging info for our little gorg + +require 'syslog' +require 'webrick/log' + +module Gorg + # Make log functions available as if we were inside a log instance + # If no $Log global variable has been initialized, do nothing + def fatal(msg) $Log.fatal(msg) if $Log; end + def error(msg) $Log.error(msg) if $Log; end + def warn(msg) $Log.warn(msg) if $Log; end + def info(msg) $Log.info(msg) if $Log; end + def debug(msg) $Log.debug(msg) if $Log; end + + module Log + + class MyLog < WEBrick::BasicLog + # Interface to WEBrick log system + # Not much to add at this time ;-) + end + + class MySyslog + # Interface to syslog + def initialize(appname) + # Open syslog if not already done (only one open is allowed) + @@syslog = Syslog.open(appname) unless defined?(@@syslog) + # Make sure messages get through (WEBrick has its own filter) + @@syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_ERR) + end + + def <<(str) + # WEBrick's logging requires the << method + # Just forward string to syslog + @@syslog.err(str) + end + end + end +end |