| |
- builtins.object
-
- ColoredLogger
- logging.Formatter(builtins.object)
-
- CsvFormatter
- logging.handlers.RotatingFileHandler(logging.handlers.BaseRotatingHandler)
-
- CompressLogHandler
class ColoredLogger(builtins.object) |
|
ColoredLogger(logger: logging.Logger)
This class implements a colored logger. |
|
Methods defined here:
- __init__(self, logger: logging.Logger)
- Initialize self. See help(type(self)) for accurate signature.
- critical(self, log: str) -> None
- This function logs a colored critical message.
- debug(self, log: str) -> None
- This function logs a colored debug message.
- error(self, log: str) -> None
- This function logs a colored error message.
- info(self, log: str) -> None
- This function logs a colored info message.
- warning(self, log: str) -> None
- This function logs a colored warning message.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class CompressLogHandler(logging.handlers.RotatingFileHandler) |
|
CompressLogHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None)
This class implements a handler to compress and rotate log files. |
|
- Method resolution order:
- CompressLogHandler
- logging.handlers.RotatingFileHandler
- logging.handlers.BaseRotatingHandler
- logging.FileHandler
- logging.StreamHandler
- logging.Handler
- logging.Filterer
- builtins.object
Methods defined here:
- doRollover(self)
- Do a rollover, as described in __init__().
- namer(self, name: str) -> str
- This function returns the new name of the old log files.
- rotator(self, source: str, destination: str) -> None
- This function compresses old log files.
Methods inherited from logging.handlers.RotatingFileHandler:
- __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None)
- Open the specified file and use it as the stream for logging.
By default, the file grows indefinitely. You can specify particular
values of maxBytes and backupCount to allow the file to rollover at
a predetermined size.
Rollover occurs whenever the current log file is nearly maxBytes in
length. If backupCount is >= 1, the system will successively create
new files with the same pathname as the base file, but with extensions
".1", ".2" etc. appended to it. For example, with a backupCount of 5
and a base file name of "app.log", you would get "app.log",
"app.log.1", "app.log.2", ... through to "app.log.5". The file being
written to is always "app.log" - when it gets filled up, it is closed
and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc.
exist, then they are renamed to "app.log.2", "app.log.3" etc.
respectively.
If maxBytes is zero, rollover never occurs.
- shouldRollover(self, record)
- Determine if rollover should occur.
Basically, see if the supplied record would cause the file to exceed
the size limit we have.
Methods inherited from logging.handlers.BaseRotatingHandler:
- emit(self, record)
- Emit a record.
Output the record to the file, catering for rollover as described
in doRollover().
- rotate(self, source, dest)
- When rotating, rotate the current log.
The default implementation calls the 'rotator' attribute of the
handler, if it's callable, passing the source and dest arguments to
it. If the attribute isn't callable (the default is None), the source
is simply renamed to the destination.
:param source: The source filename. This is normally the base
filename, e.g. 'test.log'
:param dest: The destination filename. This is normally
what the source is rotated to, e.g. 'test.log.1'.
- rotation_filename(self, default_name)
- Modify the filename of a log file when rotating.
This is provided so that a custom filename can be provided.
The default implementation calls the 'namer' attribute of the
handler, if it's callable, passing the default name to
it. If the attribute isn't callable (the default is None), the name
is returned unchanged.
:param default_name: The default name for the log file.
Methods inherited from logging.FileHandler:
- __repr__(self)
- Return repr(self).
- close(self)
- Closes the stream.
Methods inherited from logging.StreamHandler:
- flush(self)
- Flushes the stream.
- setStream(self, stream)
- Sets the StreamHandler's stream to the specified value,
if it is different.
Returns the old stream, if the stream was changed, or None
if it wasn't.
Data and other attributes inherited from logging.StreamHandler:
- terminator = '\n'
Methods inherited from logging.Handler:
- acquire(self)
- Acquire the I/O thread lock.
- createLock(self)
- Acquire a thread lock for serializing access to the underlying I/O.
- format(self, record)
- Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- get_name(self)
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- handleError(self, record)
- Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
- release(self)
- Release the I/O thread lock.
- setFormatter(self, fmt)
- Set the formatter for this handler.
- setLevel(self, level)
- Set the logging level of this handler. level must be an int or a str.
- set_name(self, name)
Data descriptors inherited from logging.Handler:
- name
Methods inherited from logging.Filterer:
- addFilter(self, filter)
- Add the specified filter to this handler.
- filter(self, record)
- Determine if a record is loggable by consulting all the filters.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
.. versionchanged:: 3.2
Allow filters to be just callables.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
Data descriptors inherited from logging.Filterer:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class CsvFormatter(logging.Formatter) |
|
This class implements a CSV logging formatter. |
|
- Method resolution order:
- CsvFormatter
- logging.Formatter
- builtins.object
Methods defined here:
- __init__(self)
- Initialize the formatter with specified format strings.
Initialize the formatter either with the specified format string, or a
default as described above. Allow for specialized date formatting with
the optional datefmt argument. If datefmt is omitted, you get an
ISO8601-like (or RFC 3339-like) format.
Use a style parameter of '%', '{' or '$' to specify that you want to
use one of %-formatting, :meth:`str.format` (``{}``) formatting or
:class:`string.Template` formatting in your format string.
.. versionchanged:: 3.2
Added the ``style`` parameter.
- format(self, record)
- This function formats record in CSV.
Methods inherited from logging.Formatter:
- formatException(self, ei)
- Format and return the specified exception information as a string.
This default implementation just uses
traceback.print_exception()
- formatMessage(self, record)
- formatStack(self, stack_info)
- This method is provided as an extension point for specialized
formatting of stack information.
The input data is a string as returned from a call to
:func:`traceback.print_stack`, but with the last trailing newline
removed.
The base implementation just returns the value passed in.
- formatTime(self, record, datefmt=None)
- Return the creation time of the specified LogRecord as formatted text.
This method should be called from format() by a formatter which
wants to make use of a formatted time. This method can be overridden
in formatters to provide for any specific requirement, but the
basic behaviour is as follows: if datefmt (a string) is specified,
it is used with time.strftime() to format the creation time of the
record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used.
The resulting string is returned. This function uses a user-configurable
function to convert the creation time to a tuple. By default,
time.localtime() is used; to change this for a particular formatter
instance, set the 'converter' attribute to a function with the same
signature as time.localtime() or time.gmtime(). To change it for all
formatters, for example if you want all logging times to be shown in GMT,
set the 'converter' attribute in the Formatter class.
- usesTime(self)
- Check if the format uses the creation time of the record.
Static methods inherited from logging.Formatter:
- converter = localtime(...)
- localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,
tm_sec,tm_wday,tm_yday,tm_isdst)
Convert seconds since the Epoch to a time tuple expressing local time.
When 'seconds' is not passed in, convert the current time instead.
Data descriptors inherited from logging.Formatter:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from logging.Formatter:
- default_msec_format = '%s,%03d'
- default_time_format = '%Y-%m-%d %H:%M:%S'
| |