Author: remi
Date: 2008-12-13 16:36:11 +0100 (Sat, 13 Dec 2008)
New Revision: 3082
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/logger/SimpleLogger.py
Log:
* updated doc and comments
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/logger/SimpleLogger.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/logger/SimpleLogger.py
2008-12-13 15:27:10 UTC (rev 3081)
+++
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/logger/SimpleLogger.py
2008-12-13 15:36:11 UTC (rev 3082)
@@ -1,4 +1,4 @@
-# -*- coding: latin1 -*-
+# -*- coding: utf-8 -*-
import version
__author__ = version.author
@@ -7,8 +7,8 @@
__licence__ = version.licence
del version
-# Copyright (C) 2008 C2ME Sa
-# R�mi Jocaille <[email protected]>
+# Copyleft (C) 2008 C2ME Sa
+# Remi Jocaille <[email protected]>
# Distributed under the terms of the GNU General Public License
# http://www.gnu.org/copyleft/gpl.html
@@ -16,25 +16,36 @@
import threading
import time
+# Levels
LOG_LEVEL_DEBUG = 0
LOG_LEVEL_INFO = 1
LOG_LEVEL_WARNING = 2
LOG_LEVEL_ERROR = 3
LOG_LEVEL_NONE = 4
-
+# Targets
LOG_TARGET_FILE = 0
LOG_TARGET_SHELL = 1
LOG_TARGET_BOTH = 2
LOG_TARGET_NONE = 3
+#
==============================================================================
+# Public class
+#
==============================================================================
+
+#
------------------------------------------------------------------------------
+# Simple logger for python.
+#
------------------------------------------------------------------------------
class SimpleLogger(object):
"""Simple logger for python.
"""
+ #
--------------------------------------------------------------------------
+ # Constructor.
+ #
--------------------------------------------------------------------------
def __init__(self, appName, logPath = None):
"""Constructor of the class.
-
@param appName: name of the application.
+ @param logPath: Output path of the log file.
"""
self.__level = LOG_LEVEL_ERROR
self.__target = LOG_TARGET_BOTH
@@ -53,28 +64,38 @@
self.__logFileName = os.path.join(self.__logPath, self.__logName)
self.__logMutex = threading.Lock()
+ #
--------------------------------------------------------------------------
+ # Get the log file path.
+ #
--------------------------------------------------------------------------
def getLogFilePath(self):
"""Get the log file path.
@return : The path to the log file.
"""
return self.__logFileName
+ #
--------------------------------------------------------------------------
+ # Set the log level.
+ #
--------------------------------------------------------------------------
def setLevel(self, level):
"""Set the log level.
-
@param level: (LOG_LEVEL_DEBUG|LOG_LEVEL_INFO|LOG_LEVEL_WARNING
LOG_LEVEL_ERROR|LOG_LEVEL_NONE)
"""
self.__level = level
+ #
--------------------------------------------------------------------------
+ # Set the log target.
+ #
--------------------------------------------------------------------------
def setTarget(self, target):
"""Set the log target.
-
@param target: (LOG_TARGET_FILE|LOG_TARGET_SHELL|LOG_TARGET_BOTH
LOG_TARGET_NONE)
"""
self.__target = target
+ #
--------------------------------------------------------------------------
+ # Reset the log file.
+ #
--------------------------------------------------------------------------
def resetLog(self):
"""Reset the log file.
"""
@@ -84,9 +105,12 @@
except:
pass
+ #
--------------------------------------------------------------------------
+ # Put a message in the log.
+ #
--------------------------------------------------------------------------
def __putLog(self, msgType, msgString):
+ """Put a message in the log.
"""
- """
message = "[%s] at (%s) : %s" % (msgType, self.__getTimeInfo(),
msgString)
if self.__target in [LOG_TARGET_FILE, LOG_TARGET_BOTH]:
@@ -99,43 +123,54 @@
if self.__target in [LOG_TARGET_SHELL, LOG_TARGET_BOTH]:
print message
+ #
--------------------------------------------------------------------------
+ # Get the current time.
+ #
--------------------------------------------------------------------------
def __getTimeInfo(self):
+ """Get the current time.
"""
- """
now = time.localtime()
timeInfo = "%.2d:%.2d:%.2d" % (now[3], now[4], now[5])
return timeInfo
+ #
--------------------------------------------------------------------------
+ # Insert an error message in the log file.
+ #
--------------------------------------------------------------------------
def logError(self, message):
- """Inser an error message in the log file.
-
+ """Insert an error message in the log file.
@param message: message to log.
"""
if self.__level > LOG_LEVEL_ERROR:
return
self.__putLog("Error", message)
+ #
--------------------------------------------------------------------------
+ # Insert a warning message in the log file.
+ #
--------------------------------------------------------------------------
def logWarning(self, message):
- """Inser a warning message in the log file.
-
+ """Insert a warning message in the log file.
@param message: message to log.
"""
if self.__level > LOG_LEVEL_WARNING:
return
self.__putLog("Warning", message)
+ #
--------------------------------------------------------------------------
+ # Insert an info message in the log file.
+ #
--------------------------------------------------------------------------
def logInfo(self, message):
- """Inser an info message in the log file.
-
+ """Insert an info message in the log file.
@param message: message to log.
"""
if self.__level > LOG_LEVEL_INFO:
return
self.__putLog("Info", message)
+ #
--------------------------------------------------------------------------
+ # Insert a debug message in the log file.
+ #
--------------------------------------------------------------------------
def logDebug(self, message):
- """Inser a debug message in the log file.
-
+ """Insert a debug message in the log file.
@param message: message to log.
"""
if self.__level > LOG_LEVEL_DEBUG:
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn