Logging¶

Structlog based beautiful logging.
This configuration offers YAML rendering for the json
key in every log
calls.
import cli2
cli2.log.warn("something happened", custom=key, json=will_be_prettyfied)
In general, you’ll want to use want to use:
log.debug()
: to indicate that something is going to happen, or a request is being sentlog.info()
: to indicate that something has happened, or a response was receivedlog.warn()
: something hasn’t happened as expected, but your program can recover from that (ie. retrying a connection)log.error()
: your program couldn’t perform some functionlog.critical()
: your program may not be able to continue running
Anyway, it’s structlog so you can also create bound loggers that will carry on the given parameters:
import cli2
log = cli2.log.bind(some='var')
log.warn('hello') # will log with some=var
Log level is set to warning by default, configurable over environment variables.
- LOG_LEVEL¶
Setting this to
INFO
,DEBUG
, or any other log level is safe.
- DEBUG¶
Setting this will set
LOG_LEVEL
to DEBUG, but also activate otherwise hidden outputs, such as, in cli2.client: long pagination outputs, secret/masked variables. This variable is designed to never be enabled in automated runs, to avoid leaking way to much information in say Ansible Tower and stuff like that. But if you’re debugging manually, you will surely need that at some point.