pds4_tools.utils.logging module¶
Classes¶
PDS4Logger (*args, **kwargs) |
Customer Logger that supports getting handlers by name, has quiet() and loud() methods and where each logging message can have a maximum number of repetitions set. |
PDS4StreamHandler (name[, level]) |
Custom StreamHandler that has a name and a is_quiet attributes. |
PDS4SilentHandler (name) |
Custom StreamHandler that saves emitted records to records attribute. |
PDS4Formatter ([fmt, datefmt]) |
Custom formatter that varies format according to log level. |
Functions¶
logger_init () |
Initializes or obtains the logger and its handlers. |
Details¶
-
class
PDS4Logger
(*args, **kwargs)[source]¶ Bases:
logging.Logger
,object
Customer Logger that supports getting handlers by name, has quiet() and loud() methods and where each logging message can have a maximum number of repetitions set.
-
get_handler
(handler_name)[source]¶ Obtain handler by name.
Parameters: handler_name : str or unicode
The name of the handler.
Returns: PDS4StreamHandler or PDS4SilentHandler
Handler for this logger, matching the handler_name.
-
quiet
(handler_name=u'stdout_handler')[source]¶ Sets a handler to log only errors.
Parameters: handler_name : str or unicode, optional
Handler name to select. Defaults to stdout handler.
Returns: None
-
-
class
PDS4StreamHandler
(name, level=10)[source]¶ Bases:
logging.StreamHandler
Custom StreamHandler that has a name and a is_quiet attributes.
-
name
¶ Returns: str or unicode
Name of the handler.
-
is_quiet
¶ Returns: bool
True if handler is quiet, False otherwise.
-
set_level
(level)[source]¶ Set handler log level.
Convenience method for setLevel.
Parameters: level : int
Level to set for handler. See Python documentation on logger levels for details.
-
-
class
PDS4SilentHandler
(name)[source]¶ Bases:
pds4_tools.utils.logging.PDS4StreamHandler
Custom StreamHandler that saves emitted records to records attribute.
Able to print out previously emitted records via
to_string
.-
name
¶ Returns: str or unicode
Name of the handler.
-
is_quiet
¶ Returns: bool
True if handler is quiet, False otherwise.
-
get_level
()¶ Get handler log level.
Convenience method for the level attribute.
Returns: int
Level for handler. See Python do cumentation on logger levels for details.
-
set_level
(level)¶ Set handler log level.
Convenience method for setLevel.
Parameters: level : int
Level to set for handler. See Python documentation on logger levels for details.
-
setLevel
(level)¶ Set handler log level.
Overloads
logging.StreamHandler.setLevel
to automatically set whether logger is quiet or loud.Parameters: level : int
Level to set for handler. See Python documentation on logger levels for details.
-
emit
(record)[source]¶ Saves emitted record.
Parameters: record : logger.LogRecord
Record to emit.
Returns: None
-
begin_recording
()[source]¶ Used in conjunction with
get_recording
. Records emitted after this method is called will be returned byget_recording
.Returns: None
-
get_recording
(reset=True)[source]¶ Obtains records since
begin_recording
was called as a joined string.Parameters: reset : bool, optional
If True, begins a new recording from now on. If False, recording from previous point continues. Defaults to True.
Returns: str or unicode
A string containing the messages that were emitted since
begin_recording
was called.Raises: RuntimeError
Raised if
begin_recording
was not called prior to calling this method.
-
to_string
(start_i=0, end_i=None)[source]¶ Output emitted records as a joined string.
Parameters: start_i : int, optional
Index of first record to include. Defaults to 0 (include records from the beginning).
end_i : int, optional
Index of last record to include. Defaults to None (include records until the end).
Returns: str or unicode
A string containing the messages in the records that were previously emitted.
-