Welcome to pysimplelog’s documentation!

Usage

# 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.")

output


    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.

class pysimplelog.SimpleLog.Logger(name='logger', flush=True, logToStdout=True, stdout=None, logToFile=True, logFileBasename='simplelog', logFileExtension='log', logFileMaxSize=10, stdoutMinLevel=None, stdoutMaxLevel=None, fileMinLevel=None, fileMaxLevel=None)

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:
  1. name (string): The logger name.
  2. flush (boolean): Whether to always flush the logging streams.
  3. logToStdout (boolean): Whether to log to the standard output stream.
  4. stdout (None, stream): The standard output stream. If None, system standard output will be set automatically. Otherwise any stream with read and write methods can be passed
  5. logToFile (boolean): Whether to log to to file.
  6. logFileBasename (string): Logging file basename. A logging file full name is set as logFileBasename.logFileExtension
  7. logFileExtension (string): Logging file extension. A logging file full name is set as logFileBasename.logFileExtension
  8. logFileMaxSize (number): The maximum size in Megabytes of a logging file. Once exceeded, another logging file as logFileBasename_N.logFileExtension will be created. Where N is an automatically incremented number.
  9. stdoutMinLevel(None, number): The minimum logging to system standard output level. If None, standard output minimum level checking is left out.
  10. stdoutMaxLevel(None, number): The maximum logging to system standard output level. If None, standard output maximum level checking is left out.
  11. fileMinLevel(None, number): The minimum logging to file level. If None, file minimum level checking is left out.
  12. fileMaxLevel(None, number): The maximum logging to file level. If None, file maximum level checking is left out.
logTypes

list of all defined log types.

logLevels

dictionary copy of all defined log types levels.

logTypeFileFlags

dictionary copy of all defined log types logging to a file flags.

logTypeStdoutFlags

dictionary copy of all defined log types logging to Standard output flags.

stdoutMinLevel

Standard output minimum logging level.

stdoutMaxLevel

Standard output maximum logging level.

fileMinLevel

file logging minimum level.

fileMaxLevel

file logging maximum level.

forcedStdoutLevels

dictionary copy of forced flags of logging to standard output.

forcedFileLevels

dictionary copy of forced flags of logging to file.

logTypeNames

dictionary copy of all defined log types logging names.

logTypeLevels

dictionary copy of all defined log types levels showing when logging.

logTypeFormats

dictionary copy of all defined log types format showing when logging.

name

logger name.

logToStdout

log to stdout flag.

logToFile

log to file flag.

logFileName

currently used log file name.

logFileBasename

log file basename.

logFileExtension

log file extension.

logFileMaxSize

maximum allowed logfile size in megabytes.

set_name(name)

Set the logger name.

Parameters:
  1. name (string): The logger name.
set_flush(flush)

Set the logger flush flag.

Parameters:
  1. flush (boolean): Whether to always flush the logging streams.
set_stdout(stream=None)

Set the logger standard output stream.

Parameters:
  1. stdout (None, stream): The standard output stream. If None, system standard output will be set automatically. Otherwise any stream with read and write methods can be passed
set_log_to_stdout_flag(logToStdout)

Set the logging to the defined standard output flag.

Parameters:
  1. logToStdout (boolean): Whether to log to the standard output stream.
set_log_to_file_flag(logToFile)

Set the logging to a file flag.

Parameters:
  1. logToFile (boolean): Whether to log to to file.
set_log_type_flags(logType, stdoutFlag, fileFlag)

Set a defined log type flags.

Parameters:
  1. logType (string): A defined logging type.
  2. stdoutFlag (boolean): Whether to log to the standard output stream.
  3. fileFlag (boolean): Whether to log to to file.
set_log_file_extension(logFileExtension)

Set the log file extension.

Parameters:
  1. logFileExtension (string): Logging file extension. A logging file full name is set as logFileBasename.logFileExtension
set_log_file_basename(logFileBasename)

Set the log file basename.

Parameters:
  1. logFileBasename (string): Logging file basename. A logging file full name is set as logFileBasename.logFileExtension
set_log_file_maximum_size(logFileMaxSize)

Set the log file maximum size in megabytes

Parameters:
  1. logFileMaxSize (number): The maximum size in Megabytes of a logging file. Once exceeded, another logging file as logFileBasename_N.logFileExtension will be created. Where N is an automatically incremented number.
set_minimum_level(level=0, stdoutFlag=True, fileFlag=True)

Set the minimum logging level. All levels below the minimum will be ignored at logging.

Parameters:
  1. level (None, number, str): The minimum level of logging. If None, minimum level checking is left out. If str, it must be a defined logtype and therefore the minimum level would be the level of this logtype.
  2. stdoutFlag (boolean): Whether to apply this minimum level to standard output logging.
  3. fileFlag (boolean): Whether to apply this minimum level to file logging.
set_maximum_level(level=0, stdoutFlag=True, fileFlag=True)

Set the maximum logging level. All levels above the maximum will be ignored at logging.

Parameters:
  1. level (None, number, str): The maximum level of logging. If None, maximum level checking is left out. If str, it must be a defined logtype and therefore the maximum level would be the level of this logtype.
  2. stdoutFlag (boolean): Whether to apply this maximum level to standard output logging.
  3. fileFlag (boolean): Whether to apply this maximum level to file logging.
force_log_type_stdout_flag(logType, flag)

Force a logtype standard output logging flag despite minimum and maximum logging level boundaries.

Parameters:
  1. logType (string): A defined logging type.
  2. flag (None boolean): The standard output logging flag. If None, logtype existing forced flag is released.
force_log_type_file_flag(logType, flag)

Force a logtype file logging flag despite minimum and maximum logging level boundaries.

Parameters:
  1. logType (string): A defined logging type.
  2. flag (None, boolean): The file logging flag. If None, logtype existing forced flag is released.
force_log_type_flags(logType, stdoutFlag, fileFlag)

Force a logtype logging flags.

Parameters:
  1. logType (string): A defined logging type.
  2. stdoutFlag (None, boolean): The standard output logging flag. If None, logtype stdoutFlag forcing is released.
  3. fileFlag (None, boolean): The file logging flag. If None, logtype fileFlag forcing is released.
set_log_type_name(logType, name)

Set a logtype name.

Parameters:
  1. logType (string): A defined logging type.
  2. name (string): The logtype new name.
set_log_type_level(logType, level)

Set a logtype logging level.

Parameters:
  1. logType (string): A defined logging type.
  2. level (number): The level of logging.
remove_log_type(logType, _assert=False)

Remove a logtype.

Parameters:
  1. logType (string): The logtype.
  2. _assert (boolean): Raise an assertion error if logType is not defined.
add_log_type(logType, name=None, level=0, stdoutFlag=None, fileFlag=None, color=None, highlight=None, attributes=None)

Add a new logtype.

Parameters:
  1. logType (string): The logtype.

  2. name (None, string): The logtype name. If None, name will be set to logtype.

  3. level (number): The level of logging.

  4. stdoutFlag (None, boolean): Force standard output logging flag. If None, flag will be set according to minimum and maximum levels.

  5. fileFlag (None, boolean): Force file logging flag. If None, flag will be set according to minimum and maximum levels.

  6. color (None, string): The logging text color. The defined colors are:

    black , red , green , orange , blue , magenta , cyan , grey , dark grey , light red , light green , yellow , light blue , pink , light cyan

  7. highlight (None, string): The logging text highlight color. The defined highlights are:

    black , red , green , orange , blue , magenta , cyan , grey

  8. attributes (None, string): The logging text attribute. The defined attributes are:

    bold , underline , blink , invisible , strike through

N.B logging color, highlight and attributes are not allowed on all types of streams.

update_log_type(logType, name=None, level=None, stdoutFlag=None, fileFlag=None, color=None, highlight=None, attributes=None)

update a logtype.

Parameters:
  1. logType (string): The logtype.

  2. name (None, string): The logtype name. If None, name will be set to logtype.

  3. level (number): The level of logging.

  4. stdoutFlag (None, boolean): Force standard output logging flag. If None, flag will be set according to minimum and maximum levels.

  5. fileFlag (None, boolean): Force file logging flag. If None, flag will be set according to minimum and maximum levels.

  6. color (None, string): The logging text color. The defined colors are:

    black , red , green , orange , blue , magenta , cyan , grey , dark grey , light red , light green , yellow , light blue , pink , light cyan

  7. highlight (None, string): The logging text highlight color. The defined highlights are:

    black , red , green , orange , blue , magenta , cyan , grey

  8. attributes (None, string): The logging text attribute. The defined attributes are:

    bold , underline , blink , invisible , strike through

N.B logging color, highlight and attributes are not allowed on all types of streams.

log(logType, message)

log a message of a certain logtype.

Parameters:
  1. logType (string): A defined logging type.
  2. message (string): Any message to log.
force_log(logType, message, stdout=True, file=True)

Force logging a message of a certain logtype whether logtype level is allowed or not.

Parameters:
  1. logType (string): A defined logging type.
  2. message (string): Any message to log.
  3. stdout (boolean): Whether to force logging to standard output.
  4. file (boolean): Whether to force logging to file.
flush()

Flush all streams.

info(message)

alias to message at information level

information(message)

alias to message at information level

warn(message)

alias to message at warning level

warning(message)

alias to message at warning level

error(message)

alias to message at error level

critical(message)

alias to message at critical level

debug(message)

alias to message at debug level