Welcome to jaraco.logging documentation!

class jaraco.logging.LogFileWrapper(name, lvl=10)

Bases: object

Emulates a file to replace stdout or stderr or anothe file object and redirects its output to a logger.

Since data will often be send in partial lines or multiple lines, data is queued up until a new line is received. Each line of text is send to the logger separately.

write(data)
class jaraco.logging.TimestampFileHandler(base_filename, mode='a', period='day')

Bases: logging.StreamHandler

A logging handler which will log to a file, similar to logging.handlers.RotatingFileHandler, but instead of appending a number, uses a timestamp to periodically select new file names to log to.

Since this was developed, a TimedRotatingFileHandler was added to the Python stdlib. This class is still useful because it allows the period to be specified using simple english words.

close()

Closes the stream.

emit(record)

Emit a record.

Output the record to the file, ensuring that the currently- opened file has the correct date.

get_filename(t)

Return the appropriate filename for the given time based on the defined period.

property period
jaraco.logging.add_arguments(parser, default_level=20)

Add arguments to an ArgumentParser or OptionParser for purposes of grabbing a logging level.

>>> import argparse
>>> add_arguments(argparse.ArgumentParser())
jaraco.logging.log_level(level_string)

Return a log level for a string

>>> log_level('DEBUG') == logging.DEBUG
True
>>> log_level('30') == logging.WARNING
True
jaraco.logging.setup(options, **kwargs)

Setup logging with options or arguments from an OptionParser or ArgumentParser. Also pass any keyword arguments to the basicConfig call.

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> add_arguments(parser)
>>> monkeypatch = getfixture('monkeypatch')
>>> monkeypatch.setattr(logging, 'basicConfig', lambda **kwargs: print(kwargs))
>>> setup(parser.parse_args([]))
{'level': 20}
jaraco.logging.setup_requests_logging(level)

Setup logging for ‘requests’ such that it logs details about the connection, headers, etc.

>>> monkeypatch = getfixture('monkeypatch')
>>> monkeypatch.setattr(http.client.HTTPConnection, 'debuglevel', None)
>>> setup_requests_logging(logging.DEBUG)
>>> http.client.HTTPConnection.debuglevel
True

Indices and tables