Package entropy :: Module misc :: Class LogFile

Class LogFile

source code

Entropy simple logging interface, works as file object

Instance Methods
 
__init__(self, level=0, filename=None, header='[LOG]')
LogFile constructor.
source code
 
__del__(self) source code
 
close(self)
Close log file
source code
 
get_fpath(self)
Get log file path
source code
 
flush(self)
Flush log file buffer to disk
source code
int
fileno(self)
Get log file descriptor number
source code
bool
isatty(self)
Return whether LogFile works like a tty
source code
string
read(self, *args)
Fake method (exposed for file object compatibility)
source code
string
readline(self)
Fake method (exposed for file object compatibility)
source code
list
readlines(self)
Fake method (exposed for file object compatibility)
source code
int
seek(self, offset)
File object method, move file object cursor at offset
source code
int
tell(self)
File object method, tell file object position
source code
 
truncate(self)
File object method, truncate file buffer.
source code
 
open(self, file_path=None)
Open log file, if possible, otherwise redirect to /dev/null or stderr.
source code
 
__call__(self, format, *args) source code
 
default_handler(self, mystr)
Default log file writer.
source code
 
set_loglevel(self, level)
Change logging threshold.
source code
 
log(self, messagetype, level, message)
This is the effective function that LogFile consumers should use.
source code
 
write(self, mystr)
File object method, write log message to file using the default handler set (LogFile.default_handler is the default).
source code
 
writelines(self, lst)
File object method, write log message strings to file using the default handler set (LogFile.default_handler is the default).
source code
Method Details

__init__(self, level=0, filename=None, header='[LOG]')
(Constructor)

source code 

LogFile constructor.

Parameters:
  • level (int) - log level threshold which will trigger effective write on log file
  • filename (string) - log file path
  • header (string) - log line header

fileno(self)

source code 

Get log file descriptor number

Returns: int
file descriptor number

isatty(self)

source code 

Return whether LogFile works like a tty

Returns: bool
is a tty?

read(self, *args)

source code 

Fake method (exposed for file object compatibility)

Returns: string
empty string

readline(self)

source code 

Fake method (exposed for file object compatibility)

Returns: string
empty string

readlines(self)

source code 

Fake method (exposed for file object compatibility)

Returns: list
empty list

seek(self, offset)

source code 

File object method, move file object cursor at offset

Returns: int
new file object position

tell(self)

source code 

File object method, tell file object position

Returns: int
file object position

open(self, file_path=None)

source code 

Open log file, if possible, otherwise redirect to /dev/null or stderr.

Parameters:
  • file_path (string) - path to file

default_handler(self, mystr)

source code 

Default log file writer. This can be reimplemented.

Parameters:
  • mystr (string) - log string to write

set_loglevel(self, level)

source code 

Change logging threshold.

Parameters:
  • level (int) - new logging threshold

log(self, messagetype, level, message)

source code 

This is the effective function that LogFile consumers should use.

Parameters:
  • messagetype (string) - message type (or tag)
  • level (int) - minimum logging threshold which should trigger the effective write
  • message (string) - log message

write(self, mystr)

source code 

File object method, write log message to file using the default handler set (LogFile.default_handler is the default).

Parameters:
  • mystr (string) - log string to write

writelines(self, lst)

source code 

File object method, write log message strings to file using the default handler set (LogFile.default_handler is the default).

Parameters:
  • lst (list) - list of strings to write