Put all of the menu handling code in View.
[matthijs/upstream/mobilegtd.git] / src / log / logging.py
1 import os
2 from inout import io
3
4 class FileLogger:
5     def __init__(self,file_path=u'C:/mobile_gtd.log',log_level = 8):
6         self.entries = []
7         self.file_path = file_path
8         self.file_path = 'C:/Data/GTD/mobile_gtd.log'
9         self.log_level = log_level
10         #self.log_file = file(io.os_encode(file_path),'w')
11         io.create_file(self.file_path).close
12         self.log_file = file(self.file_path,'a')
13     def log_stderr(self):
14         import sys
15         self.old_stderr = sys.stderr
16         sys.stderr = self.log_file
17         sys.stderr.write('stderr logged from logging\n')
18         self.log_file.flush()
19
20     def unlog_stderr(self):
21         import sys
22         sys.stderr = self.old_stderr
23     def log(self,text,level=0):
24         if level < self.log_level:          
25             self.log_file.write(io.os_encode(text)+'\n')
26             self.log_file.flush()
27     def close(self):
28         #sys.stderr.flush()
29         self.unlog_stderr()
30         self.log(u'Closing log')
31         self.log_file.flush()
32         self.log_file.close()
33         
34         
35
36 class ConsoleLogger:
37     def __init__(self,log_level = 8):
38         self.log_level = log_level
39     def log(self,text,level=0):
40         import appuifw
41         if level < self.log_level:
42             appuifw.note(u''+repr(text))
43     def close(self):
44         pass
45
46 class NullLogger:
47     def log(self,text,level=0):
48         pass
49     def log_stderr(self):
50         pass
51     def close(self):
52         pass
53         
54 #logger=FileLogger(gtd_directory+'gtd.log')
55 # Need NullLogger during initialization of FileLogger
56 #logger=NullLogger()
57 logger=FileLogger()
58 #logger=ConsoleLogger()