Logging¶
redsun logs everything to the redsun logger. Usage is in
Configure logging.
| Symbol | What it does |
|---|---|
set_level |
sets the level of the redsun logger |
add_handler |
sends the logger's records to one more handler |
remove_handler |
stops sending records to a handler |
Loggable |
gives a component a logger that names the component in each record |
BufferHandler |
keeps the most recent records of the session in memory |
log_buffer |
returns the BufferHandler installed on the logger |
SessionFileHandler |
writes the records of one run of a session to a rotated file |
session_log |
returns the SessionFileHandler installed on the logger, or on a service's, if any |
service_of |
names the service a record came from |
The built-in LogView shows these records in
the application.
Functions¶
set_level
¶
Set the level of the redsun logger.
Level names are case-insensitive.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a name names no level. |
Source code in src/redsun/log.py
add_handler
¶
Send the redsun logger's records to handler as well.
With a service, only that service's records reach handler. A handler without a formatter gets the shared one, so records read the same everywhere.
Source code in src/redsun/log.py
remove_handler
¶
Stop sending the records add_handler sent to handler.
A handler that is not installed is left alone.
log_buffer
¶
Return the buffer holding this session's log records.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the logging configuration no longer carries a buffer. |
Source code in src/redsun/log.py
session_log
¶
Return the handler writing this run's log file, if a session opened one.
With a service, the handler writing that service's file.
Source code in src/redsun/log.py
service_of
¶
Return the name of the service record came from, None for the application.
Source code in src/redsun/log.py
Logging from a component¶
Session records¶
Bases: Handler
Retain the most recent log records, and announce each one as it arrives.
A consumer built later in the session can still show earlier records. Application records and each service's records are kept apart, each dropping its oldest when full, so a noisy service drops only its own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capacity
|
int
|
How many application records to retain. |
APPLICATION_CAPACITY
|
service_capacity
|
int
|
How many records of each service to retain. |
SERVICE_CAPACITY
|
Source code in src/redsun/log.py
service_capacity
property
¶
How many records of each service the buffer retains.
services
property
¶
The services a record has come from, in the order they first did.
service_records
¶
Return one service's retained records, or every service's, oldest first.
Source code in src/redsun/log.py
emit
¶
Retain record with the records of its source, and announce it.
Source code in src/redsun/log.py
Bases: RotatingFileHandler
Write the records of one run of a session to a file of its own.
The file is in the user's log directory, in a folder named after the
session, and named after the run: its start time and process. It rotates at
LOG_MAX_BYTES, keeping LOG_BACKUPS older files.
The application's file, <run>.log, takes no service records, and
opening it deletes the files of all but the session's LOG_RUNS_KEPT most
recent runs. A service's file, <run>.<service>.log, belongs to run,
is installed with add_handler(handler, service), and is created when
the service first logs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
str
|
Name of the session. |
required |
service
|
str | None
|
The service whose records the file holds, |
None
|
run
|
str | None
|
The run, as the application handler's |
None
|