Welcome to pylog’s documentation!¶
Contents:
Quick Start¶
Coming soon...
Installation¶
Coming soon...
CLI¶
Coming soon...
Configuration¶
Coming soon...
Advanced Configuration¶
Coming soon...
Formatters¶
Formatters format the logs.
Contents:
- class pylog.formatters.CustomFormatter(config)[source]¶
Bases: pylog.formatters.BaseFormatter
generates log strings in a custom format
this is also the the formatter other formatters can rely on to generate application specific logs. see the ApacheAccessFormatter class for reference.
- generate_data()[source]¶
returns a log string
for every item in the format list, if an item in the data dict corresponds with it and the field’s data equals “$RAND”, use faker to fake an item for it. else, choose one item from the list randomly. if there no item in the data to correspond with the format, it will just append to format’s field name to the log.
example: 'CustomFormatter': { 'format': ['name', ' - ', 'level'], 'data': { 'name': $RAND, 'level': ['ERROR', 'DEBUG', 'INFO', 'CRITICAL'], } }
the output of the above example might be:
Sally Fields - ERROR or Jason Banks - DEBUG or Danny Milwee - ERROR or ...
- class pylog.formatters.JsonFormatter(config)[source]¶
Bases: pylog.formatters.BaseFormatter
generates log strings in json format
- generate_data()[source]¶
returns a json string
all fields in the data dict will be iterated over. if $RAND is set in one of the fields, random data will be generate_data for that field. If not, data will be chosen from the list.
example: 'JsonFormatter': { 'data': { 'date_time': '$RAND', 'level': ['ERROR', 'DEBUG'], 'address': '$RAND', } },
the output of the above example might be:
{'date_time': '2006-11-05 13:31:09', 'name': 'Miss Nona Breitenberg DVM', 'level': 'ERROR'} # NOQA or {'date_time': '1985-01-20 11:41:16', 'name': 'Almeda Lindgren', 'level': 'DEBUG'} # NOQA or {'date_time': '1973-05-21 01:06:04', 'name': 'Jase Heaney', 'level': 'DEBUG'} # NOQA or ...
Transports¶
Transports are the methods in which logs are sent.
Contents:
API¶
Contents:
- pylog.pylog.init_logger(base_level=20, verbose_level=10, logging_config=None)[source]¶
initializes a base logger
you can use this to init a logger in any of your files. this will use config.py’s LOGGER param and logging.dictConfig to configure the logger for you.
Parameters: - base_level (int|logging.LEVEL) – desired base logging level
- verbose_level (int|logging.LEVEL) – desired verbose logging level
- logging_dict (dict) – dictConfig based configuration. used to override the default configuration from config.py
Return type: python logger
- pylog.pylog.set_global_verbosity_level(is_verbose_output=False)[source]¶
sets the global verbosity level for console and the lgr logger.
Parameters: is_verbose_output (bool) – should be output be verbose
- pylog.pylog.calculate_throughput(elapsed_time, messages)[source]¶
calculates throughput and extracts the number of seconds for the run from the elapsed time
Parameters: - elapsed_time – run time
- messages (int) – number of messages to write
Returns: throughput and seconds
Return type: tuple
- pylog.pylog.send(instance, client, format, format_config, messages, gap, batch)[source]¶
sends logs and prints the time it took to send all logs
Parameters: - instance – transport class instance
- client – client to use to send logs
- format (string) – formatter to use
- format_config (dict) – formatter configuration to use
- messages (int) – number of messages to send
- gap (float) – gap in seconds between 2 messages
- batch (int) – number of messages per batch
- pylog.pylog.config_transport(transports, transport, transport_config)[source]¶
returns a configured instance and client for the transport
Parameters: - transport (string) – transport to use
- transport_config (dict) – transport configuration
- pylog.pylog.generator(config=None, transport=None, formatter=None, gap=None, messages=None, batch=False, verbose=False)[source]¶
generates log messages
this will generate log message in the requested format and protocol.
Parameters: - config (string) – path to config file path
- transport (string) – transport type to use
- formatter (string) – formatter to use
- gap (float) – gap in seconds between 2 messages
- messages (int) – number of messages to send