root/trunk/lib/logger.py

Revision 15, 2.1 kB (checked in by mjoc, 1 year ago)

Atnaujinti vertimai. Pridėti nauji copyright'ai. Pakeista konfigūracija.

Line 
1 #
2 # OpenDict
3 # Copyright (c) 2003-2006 Martynas Jocius <martynas.jocius@idiles.com>
4 # Copyright (c) 2007 IDILES SYSTEMS, UAB <support@idiles.com>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your opinion) any later version.
10 #
11 # This program is distributed in the hope that will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MECHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more detals.
15 #
16 # You shoud have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # 02111-1307 USA
20 #
21
22 import os
23 import time
24
25 from lib import info
26
27
28 INFO = 0
29 WARNING = 1
30 ERROR = 2
31 DEBUG = 3
32
33 _logDir = os.path.join(info.LOCAL_HOME, info.LOG_DIR)
34
35 _systemLogFile = os.path.join(_logDir, 'system.log')
36 _debugLogFile = os.path.join(_logDir, 'debug.log')
37
38
39 # Enable or disable logging
40 logging = False
41
42
43 def systemLog(messageType, message):
44     """Write message system log"""
45
46     if not logging:
47         return
48
49     dateStr = time.strftime("%Y-%m-%d %H:%M:%S")
50
51     typeStr = 'ERROR'
52     if messageType == INFO:
53         typeStr = 'INFO'
54     elif messageType == WARNING:
55         typeStr = 'WARNING'
56     elif messageType == DEBUG:
57         typeStr = 'DEBUG'
58
59     try:
60         fd = open(_systemLogFile, 'a+')
61         print >> fd, dateStr, typeStr, message
62         fd.close()
63     except Exception, e:
64         print "LOGGER ERROR: Unable to write message '%s'" % repr(message)
65
66
67 def debugLog(messageType, message):
68     """Write message system log"""
69
70     if not logging:
71         return
72
73     dateStr = time.strftime("%Y-%m-%d %H:%M:%S")
74
75     typeStr = 'ERROR'
76     if messageType == INFO:
77         typeStr = 'INFO'
78     elif messageType == WARNING:
79         typeStr = 'WARNING'
80     elif messageType == DEBUG:
81         typeStr = 'DEBUG'
82
83     print dateStr, typeStr, message
84    
Note: See TracBrowser for help on using the browser.