Package: prolog
Tools and convenience methods to simplify and expedite Python logging.Simple - though opinionated - setup for common use-casesExtensively and easily configurable via user and local files, as well as environ variablesComes with full featured formatters and handlers that can also be used
in normalloggingsituationsUsagebasic_configThe easiest way to begin usingprologis to add the following to your
application code:import prolog
prolog.basic_config()This will configure therootlogger for the default levellogging.INFOand set up two handlers: a colorized, console streaming handler, as well as a file
handler set to log to the default file -pypro.log- in the main app’s directory.To specify select loggers defined in application or library code, you pass the
comma-seperated names of the desired loggers:prolog.basic_config('myapp,another_app')basic_configaccepts the following parameters:loggersThe desired loggers to configure; can be either a comma-separated
string of logger names, a list ofLoggerinstances, orNonefor the root logger.levelSpecify the logging level for all loggers and handlers. Can be
either the numeric value or string name for the desired level.handlersThe handlers to add to the givenloggers; can be a comma-separated
string of shortcut names (‘stream’ or ‘file’, by default) or a list
ofHandlerinstances.propagateIndicates whether eachloggerinstance will be set to propagte.reset_handlersIf True, force a reset of all currently configured handlers.cfgTheprolog.config.PrologConfiginstance to use. If not given,
the default will be used (prolog.config.config). For all
preceding parameters except forloggersset to None (the default),cfgwill be used to determine the appropriate setting.ExamplesOnce installed,prologcan be invoked to show configuration settings or
sample usage:$ python -m prolog sample --level=DEBUG basicSetting colors via environments variables:$ export PYPROLOG_LEVEL_COLORS='CRITICAL:white,red;ERROR:lightred;DEBUG:lightgray,cyan;*:gray,gray'
$ python -m prolog sample --level=DEBUG basicDevelop and testing$ pip install invoke
$ inv develop
$ inv testConfigurationProlog can be configured via a number of different options:User-level configuration file, usingappdirsto determine the user’s
configuration directory pluspyprolog/config, which must be a JSON encoded
file containing a dictionary overriding any of the defaults listed belowCurrent working directory configuration file.pyprologrc, also JSONEnvironment variables, see belowManipulation of the defaultprolog.config.configinstance or instantiating
your ownGenerating alogging.config.dictConfigdict viaprolog.config.dict_configDefaultsLEVEL = 'INFO'
SHORT_FMT = "{levelname}:{name} {message}"
LONG_FMT = '[{asctime} {name}:{levelname}:{module}:{lineno}] {message}'

COLOR_LONG_FMT = '{color}[{asctime} {name}:{levelname}:{module}:{lineno}]{endcolor} {message}'
COLOR_SHORT_FMT = '{color}{levelname}:{name}{endcolor} {message}'
LEVEL_COLORS = 'DEBUG:magenta;INFO:blue;WARNING:yellow;ERROR:red;CRITICAL:white,red'

DATE_FMT = "%Y-%m-%dT%H:%M:%S"
STYLE_FMT = '{'

HANDLERS = 'stream,file'
PROPAGATE = False
DISABLE_EXISTING = True
RESET_HANDLERS = True

STREAM_LEVEL = 'NOTSET'
STREAM_FORMATTER = 'color'
STREAM_STREAM = 'sys.stderr'

FILE_LEVEL = 'NOTSET'
FILE_FORMATTER = 'long'
FILE_FILENAME = 'pypro.log'
FILE_MAX_BYTES = 0
FILE_BACKUP_COUNT = 0EnvironmentBy default, theprolog.config.configinstance will load any environment
variable begging withPYPROLOG_and ending with any of the defaults listed
above. For instance, to override the default logging level, do the following
before executing your application code:$ export PYPROLOG_LEVEL='DEBUG'
$ python myapp.py