aboutsummaryrefslogtreecommitdiffstats
path: root/share/Log.py
diff options
context:
space:
mode:
authorFrederic Lepied <flepied@mandriva.com>2002-01-17 19:56:19 +0000
committerFrederic Lepied <flepied@mandriva.com>2002-01-17 19:56:19 +0000
commit68ebfc5fc46591d84ed1b0887c1c0b19ba7aa47d (patch)
tree4e2d7e6f16f8bb65f61c2913dfe35fd767e62040 /share/Log.py
parent1ff71ce4eb92eeeb629ce2669a8db801f182249c (diff)
downloadmsec-68ebfc5fc46591d84ed1b0887c1c0b19ba7aa47d.tar
msec-68ebfc5fc46591d84ed1b0887c1c0b19ba7aa47d.tar.gz
msec-68ebfc5fc46591d84ed1b0887c1c0b19ba7aa47d.tar.bz2
msec-68ebfc5fc46591d84ed1b0887c1c0b19ba7aa47d.tar.xz
msec-68ebfc5fc46591d84ed1b0887c1c0b19ba7aa47d.zip
0.17
Diffstat (limited to 'share/Log.py')
-rw-r--r--share/Log.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/share/Log.py b/share/Log.py
new file mode 100644
index 0000000..bcda819
--- /dev/null
+++ b/share/Log.py
@@ -0,0 +1,53 @@
+#---------------------------------------------------------------
+# Project : Mandrake Linux
+# Module : msec2
+# File : Log.py
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Wed Dec 5 23:50:29 2001
+# Purpose : write log through syslog conforming to
+# the Mandrake Linux guideline for the explanations
+# in tools. Errors are reported to stderr.
+#---------------------------------------------------------------
+
+import syslog
+import sys
+import string
+import Config
+
+_name = ''
+_use_syslog = 1
+
+def initlog(name, facility = syslog.LOG_AUTH):
+ global _name
+ global _use_syslog
+
+ _use_syslog = (Config.get_config('log', 'syslog') == 'syslog')
+
+ if _use_syslog:
+ syslog.openlog(name, 0, facility)
+
+ _name = name
+
+def log(s, level = syslog.LOG_INFO):
+ global _use_syslog
+
+ if _use_syslog:
+ for l in string.split(s, '\n'):
+ syslog.syslog(level, l)
+ else:
+ sys.stderr.write(s + '\n')
+ return 1
+
+def closelog():
+ global _use_syslog
+
+ if _use_syslog:
+ syslog.closelog()
+
+def error(s):
+ global _name
+
+ sys.stderr.write(_name + ': ' + s + '\n')
+
+# Log.py ends here