exopy.app.log.tools module¶
This module defines some tools to make easier the use of the logging module.
It provide tools to seamlessly convert stream information into log record so that any print can get recorded, and others to process log emitted in a subprocess.
- Contains
- StreamToLogRedirector
Simple class to redirect a stream to a logger.
- QueueHandler
Logger handler putting records into a queue.
- GuiConsoleHandler
Logger handler adding the message of a record to a GUI panel.
- QueueLoggerThread
Thread getting log record from a queue and asking logging to handle them.
-
class
exopy.app.log.tools.
StreamToLogRedirector
(logger, stream_type='stdout')[source]¶ Bases:
object
Simple class to redirect a stream to a logger.
Stream like object which can be used to replace sys.stdout, or sys.stderr.
- Parameters
logger (instance(Logger)) – Instance of a loger object returned by a call to logging.getLogger
stream_type ({'stdout', 'stderr'}, optionnal) – Type of stream being redirected. Stderr stream are logged as CRITICAL
-
logger
¶ Instance of a loger used to log the received message
- Type
instance(Logger)
-
write_info
(message)[source]¶ Log the received message as info, used for stdout.
The received message is first strip of starting and trailing whitespaces and line return.
-
class
exopy.app.log.tools.
QueueHandler
(queue)[source]¶ Bases:
logging.Handler
Handler sending events to a queue.
Typically, it would be used together with a multiprocessing Queue to centralise logging to file in one process (in a multi-process application), so as to avoid file write contention between processes. Errors are silently ignored to avoid possible recursions and that’s why this handler should be coupled to another, safer one.
- Parameters
queue – Queue to use to log the messages.
-
enqueue
(record)[source]¶ Enqueue a record.
The base implementation uses put_nowait. You may want to override this method if you want to use blocking, timeouts or custom queue implementations.
-
prepare
(record)[source]¶ Prepares a record for queueing.
The object returned by this method is enqueued. The base implementation formats the record to merge the message and arguments, and removes unpickleable items from the record in-place.
You might want to override this method if you want to convert the record to a dict or JSON string, or send a modified copy of the record while leaving the original intact.
-
class
exopy.app.log.tools.
QueueLoggerThread
(queue)[source]¶ Bases:
threading.Thread
Thread emptying a queue containing log record and sending them to the appropriate logger.
-
queue
¶ Queue from which to collect log records.
-
-
class
exopy.app.log.tools.
LogModel
[source]¶ Bases:
atom.atom.Atom
Simple object which can be used in a GuiHandler.
-
text
¶ Text representing all the messages sent by the handler. Should not be altered by user code.
-
buff_size
¶ Maximum number of lines.
-
-
class
exopy.app.log.tools.
GuiHandler
(model)[source]¶ Bases:
logging.Handler
Logger record sending the log message to an object which can be linked to a GUI.
Errors are silently ignored to avoid possible recursions and that’s why this handler should be coupled to another, safer one.
- Parameters
model (Atom) – Model object with a text member.
-
class
exopy.app.log.tools.
DayRotatingTimeHandler
(filename, mode='wb', **kwargs)[source]¶ Bases:
logging.handlers.TimedRotatingFileHandler
Custom implementation of the TimeRotatingHandler to avoid issues on win32.
Found on StackOverflow …