PyLogger Documentation

class pylogger.PyLogger(filename='pylogger.log', defaultlogtype='INFO', logformat='[{timestamp}] {logtype}: {message}', timestamp='%Y-%m-%d %H:%M:%S', prefix='', postfix='n')

The PyLogger class

Initialize a PyLogger object.

Parameters:
  • filename (str) – The filename to use
  • defaultlogtype (str) – Initial log type to use [INFO]
  • timestamp (str) – Initial timestamp format [%Y-%m-%d %H:%M:%S]
  • prefix (str) – String to insert before the log message
  • postfix (str) – String to append to the log message
open(*args)

Initialize a new logger

clear()

Clear the content of the log file

Returns:True – file cleared
Raises:IOError, Exception
delete()

Delete the log file

Returns:True – file deleted
Raises:OSError, Exception
pause()

Pause the logging until resumed

isEnabled()

Check if enabled/paused

Returns:True – enabled
resume()

Resume the logging from paused

setLogType(logtype)

Set the log type

Parameters:logtype (str) – Log type
setLogFormat(logformat)

Set custom log format

Parameters:logformat (str) – Log format Available options: {timestamp}, {logtype}, {message} Example: [{timestamp}]{logtype}: {message}
resetLogFormat()

Reset log format to default format

setTimestampFormat(timestamp)

Set custom timestamp format

Parameters:timestamp (str) – Timestamp Example: %Y-%m-%d %H:%M:%S
resetTimestampFormat()

Reset timestamp format

getTimeStamp()

Function to get the current time, returns in the timestamp format

Returns:Timestamp string
createIfNonExistent()

Create an empty log file if non existant

Returns:True – file cleared
Raises:IOError, Exception
log(logstr, logtype='')

Function to log message to file.

Parameters:
  • logstr (str) – The string you want to log
  • logtype (str) – Optional argument, custom log type. If not provided, defaults to defined log type.
Returns:

True – String has been logged to file

Raises:

IOError,Exception7

info(logstr)

Function that calls the log function with type INFO

warning(logstr)

Function that calls the log function with type WARNING

error(logstr)

Function that calls the log function with type ERROR

critical(logstr)

Function that calls the log function with type CRITICAL

exception(logstr)

Function that calls the log function with type EXCEPTION