Module tenlib.logging
Everything related to logging.
Ten exposes a log
objet that you can use to log various messages:
>>> log.info('Hello')
>>> log.debug('There')
To set the verbosity of logging in the CLI (default: none), use set_cli_level()
.
Additionally, logs are written to a log file (in ~/ten.log
by default).
To set the level of logging in this file, use set_level()
. Change the path using
set_file()
.
>>> log.info('Hello')
>>> logging.set_cli_level('DEBUG')
>>> log.error('Woops!')
[07/13/22 17:49:07] ERROR Woops ! <stdin>:1
Functions
def logger(name: str | None = 'ten') ‑> tenlib.logging.TenLogger
-
Returns a logger with the specified name or, if name is None, returns the root logger of the hierarchy.
def set_level(level: int | str | None) ‑> None
-
Sets the threshold for the file logger to
level
. Setting it toNone
disables file logging.>>> set_level("DEBUG") >>> set_level(logging.INFO) >>> set_level(None)
def set_cli_level(level: int | str | None) ‑> None
-
Sets the threshold for the CLI logger to
level
. Setting it toNone
disables CLI logging.>>> set_cli_level("DEBUG") >>> set_cli_level(logging.INFO) >>> set_cli_level(None)
def set_file(file: str | IO[str] | None) ‑> None
-
Set the location of the log file.
Args
file
- The path to the log file or a file object. Setting it to
None
disables file logging.
Example
>>> logging.set_file('/tmp/test.log') >>> logging.set_file(open('/tmp/test2.log', 'a+')) >>> logging.set_file(None)