aboutsummaryrefslogtreecommitdiffstats
path: root/share/Log.py
blob: bcda819113983521dbd305b2006249ee40c61d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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