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