File logging

This module provide two classes: Now and Logger.

The first is just a wrap around time.localtime() with human readable interface of the exact time instant the object is created. The latter is a simple file logger that uses Now instances to record information.

Created on Sat Jun 6 00:39:46 2020

@author: joaovitor

class ossom.utils.Now[source]

Human readable data about date and time.

hour

Wall clock hours.

min

Wall clock minutes.

sec

Wall clock seconds.

year

Year.

month

Month.

day

Month day.

wday

Week day.

GMT

Time zone.

class ossom.utils.Logger(name: str = 'common', ext: str = 'log', title: str = 'title', logend: str = 'end.')[source]

Simple logger.

__init__(name: str = 'common', ext: str = 'log', title: str = 'title', logend: str = 'end.') → None[source]

File based logger.

Parameters:
  • name (str, optional) – File name. The default is ‘common’.
  • ext (str, optional) – File extension. The default is ‘log’.
  • title (str, optional) – A title or description for the log. The default is ‘title’.
  • logend (str, optional) – A tag that represents the end of a logging session. The default is ‘end.’.
Returns:

Return type:

None

__del__()[source]

Close underlying file on del statement.

name

Log file name.

ext

File extension.

title

Log title.

time

Time at log creation.

header

File header.

logend

End of logging.

file

File pointer.

fopen()[source]

Open the log file, enabling read and write.

start_log()[source]

Write header to log file.

log(message: str = None) → int[source]

Write message to the log file along with the current time.

Parameters:message (str, optional) – The content of the logging. If no input is given, randomizes an item from LogFile._randlog. The default is None.
Returns:b – The amount of bytes written to log file.
Return type:int
end_log()[source]

Write the end of logging tag.

fclose()[source]

Close the log file.

print_log()[source]

Print the log file content. File must be opened.