1
2
3 import time
4 import traceback
5 from rhn.i18n import ustr, sstr
6 from up2date_client import config
7
9 """
10 attempt to log all interesting stuff, namely, anything that hits
11 the network any error messages, package installs, etc
12 """
17
20
22 if self.cfg["debug"] > 1:
23 self.log_me("D: ", *args)
24
26 """General logging function.
27 Eg: log_me("I am a banana.")
28
29 """
30 self.log_info = "[%s] %s" % (time.ctime(time.time()), self.app)
31 s = u""
32 for i in args:
33
34
35 i = ustr(str(i))
36 s += i
37 if self.cfg["debug"] > 1:
38 print(s)
39 self.write_log(s)
40
42 self.log_info = "[%s] %s" % (time.ctime(time.time()), self.app)
43 x = traceback.extract_stack()
44 msg = ''.join(traceback.format_list(x))
45 self.write_log(msg)
46
48 self.log_info = "[%s] %s" % (time.ctime(time.time()), self.app)
49 output = ["\n"]
50 output.append("Traceback (most recent call last):\n")
51 output = output + traceback.format_list(traceback.extract_tb(tb))
52 output.append("%s: %s\n" % (logtype, value))
53 self.write_log("".join(output))
54
56
57 log_name = self.cfg["logFile"] or "/var/log/up2date"
58 log_file = open(log_name, 'a')
59 msg = u"%s %s\n" % (ustr(self.log_info), ustr(s))
60 log_file.write(sstr(msg))
61 log_file.flush()
62 log_file.close()
63
65 global log
66 try:
67 log = log
68 except NameError:
69 log = None
70
71 if log == None:
72 log = Log()
73
74 return log
75