# import Logger
from pysimplelog import Logger
# initialize
l=Logger("log test")
# change log file basename from simplelog to mylog
l.set_log_file_basename("mylog")
# change log file extension from .log to .pylog
l.set_log_file_extension("pylog")
# Add new log types.
l.add_log_type("super critical", name="SUPER CRITICAL", level=200, color='red', attributes=["bold","underline"])
l.add_log_type("wrong", name="info", color='magenta', attributes=["strike through"])
l.add_log_type("important", name="info", color='black', highlight="orange", attributes=["bold"])
# update error log type
l.update_log_type(logType='error', color='pink', attributes=['underline','bold'])
# print logger
print l, '\n'
# test logging
l.info("I am info, called using my shortcut method.")
l.log("info", "I am info, called using log method.")
l.warn("I am warn, called using my shortcut method.")
l.log("warn", "I am warn, called using log method.")
l.error("I am error, called using my shortcut method.")
l.log("error", "I am error, called using log method.")
l.critical("I am critical, called using my shortcut method.")
l.log("critical", "I critical, called using log method.")
l.debug("I am debug, called using my shortcut method.")
l.log("debug", "I am debug, called using log method.")
l.log("super critical", "I am super critical, called using log method because I have no shortcut method.")
l.log("wrong", "I am wrong, called using log method because I have no shortcut method.")
l.log("important", "I am important, called using log method because I have no shortcut method.")
Logger (Version 0.2.0) log type |log name |level |std flag |file flag | ---------------|---------------|----------|----------|----------| wrong |info |0.0 |True |True | debug |DEBUG |0.0 |True |True | important |info |0.0 |True |True | info |INFO |10.0 |True |True | warn |WARNING |20.0 |True |True | error |ERROR |30.0 |True |True | critical |CRITICAL |100.0 |True |True | super critical |SUPER CRITICAL |200.0 |True |True | 2015-11-18 14:25:08 - log test <INFO> I am info, called using my shortcut method. 2015-11-18 14:25:08 - log test <INFO> I am info, called using log method. 2015-11-18 14:25:08 - log test <WARNING> I am warn, called using my shortcut method. 2015-11-18 14:25:08 - log test <WARNING> I am warn, called using log method. 2015-11-18 14:25:08 - log test <ERROR> I am error, called using my shortcut method. 2015-11-18 14:25:08 - log test <ERROR> I am error, called using log method. 2015-11-18 14:25:08 - log test <CRITICAL> I am critical, called using my shortcut method. 2015-11-18 14:25:08 - log test <CRITICAL> I critical, called using log method. 2015-11-18 14:25:08 - log test <DEBUG> I am debug, called using my shortcut method. 2015-11-18 14:25:08 - log test <DEBUG> I am debug, called using log method. 2015-11-18 14:25:08 - log test <SUPER CRITICAL> I am super critical, called using log method because I have no shortcut method.2015-11-18 14:25:08 - log test <info> I am wrong, called using log method because I have no shortcut method.2015-11-18 14:25:08 - log test <info> I am important, called using log method because I have no shortcut method.
This is simplelog main Logger class definition.
A logging is constituted of a header a message and a footer. In the current implementation the footer is empty and the header is as the following:
date time - loggerName <logTypeName>
In order to change any of the header or the footer, ‘_get_header’ and ‘_get_footer’ methods must be overloaded.
Parameters: |
|
---|
list of all defined log types.
dictionary copy of all defined log types levels.
dictionary copy of all defined log types logging to a file flags.
dictionary copy of all defined log types logging to Standard output flags.
Standard output minimum logging level.
Standard output maximum logging level.
file logging minimum level.
file logging maximum level.
dictionary copy of forced flags of logging to standard output.
dictionary copy of forced flags of logging to file.
dictionary copy of all defined log types logging names.
dictionary copy of all defined log types levels showing when logging.
dictionary copy of all defined log types format showing when logging.
logger name.
log to stdout flag.
log to file flag.
currently used log file name.
log file basename.
log file extension.
maximum allowed logfile size in megabytes.
Set the logger name.
Parameters: |
|
---|
Set the logger flush flag.
Parameters: |
|
---|
Set the logger standard output stream.
Parameters: |
|
---|
Set the logging to the defined standard output flag.
Parameters: |
|
---|
Set the logging to a file flag.
Parameters: |
|
---|
Set a defined log type flags.
Parameters: |
|
---|
Set the log file extension.
Parameters: |
|
---|
Set the log file basename.
Parameters: |
|
---|
Set the log file maximum size in megabytes
Parameters: |
|
---|
Set the minimum logging level. All levels below the minimum will be ignored at logging.
Parameters: |
|
---|
Set the maximum logging level. All levels above the maximum will be ignored at logging.
Parameters: |
|
---|
Force a logtype standard output logging flag despite minimum and maximum logging level boundaries.
Parameters: |
|
---|
Force a logtype file logging flag despite minimum and maximum logging level boundaries.
Parameters: |
|
---|
Force a logtype logging flags.
Parameters: |
|
---|
Set a logtype name.
Parameters: |
|
---|
Set a logtype logging level.
Parameters: |
|
---|
Remove a logtype.
Parameters: |
|
---|
Add a new logtype.
Parameters: |
|
---|
N.B logging color, highlight and attributes are not allowed on all types of streams.
update a logtype.
Parameters: |
|
---|
N.B logging color, highlight and attributes are not allowed on all types of streams.
log a message of a certain logtype.
Parameters: |
|
---|
Force logging a message of a certain logtype whether logtype level is allowed or not.
Parameters: |
|
---|
Flush all streams.
alias to message at information level
alias to message at information level
alias to message at warning level
alias to message at warning level
alias to message at error level
alias to message at critical level
alias to message at debug level