]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/log.py
Tell who logs that msg.
[projects/pld-builder.new.git] / PLD_Builder / log.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import sys
4 import time
5 import syslog
6
7 import path
8
9 builder = ""
10 do_syslog = 0
11
12 # string containing last log entry,
13 # as the code is flawed to get this otherwise
14 _last_log = ""
15
16 def log(p, s):
17     global _last_log
18     _last_log = s
19
20     if do_syslog:
21         try:
22             syslog.syslog(p, str(s))
23         except TypeError:
24             syslog.syslog(p, repr(s))
25     f = open(path.log_file, "a")
26     f.write("%s: %s [%s]: %s\n" % (os.path.basename(sys.argv[0]), time.asctime(), builder, s))
27     f.close()
28     
29 def panic(s):
30     log(syslog.LOG_ALERT, "PANIC: %s" % s)
31     raise Exception, "PANIC: %s" % str(s)
32
33 def alert(s):
34     log(syslog.LOG_ALERT, "alert: %s" % s) 
35  
36 def error(s):
37     log(syslog.LOG_ERR, "error: %s" % s) 
38  
39 def warn(s):
40     log(syslog.LOG_WARNING, "warning: %s" % s) 
41  
42 def notice(s):
43     log(syslog.LOG_NOTICE, "notice: %s" % s) 
44
45 def open_syslog(name, f):
46     global do_syslog
47     do_syslog = 1
48     syslog.openlog(name, syslog.LOG_PID, f)
49
50 def last_log():
51     return _last_log
This page took 0.039651 seconds and 4 git commands to generate.