module documentation

Configure logging for the OpenFlexure Server.

A module containing a custom logging handler and helper function for the OpenFlexure server. These handle formatting logs, ensuring that logs are logged both to a file and to the terminal (see note below!). Functionality is also provided for retrieving logs for to send over HTTP.

Note that when running in production OpenFlexure Microscope the server is run via systemd. As such, the logs that are sent to the terminal (STDERR) or any other output to STDOUT/STDERR are captured by systemd. These can be viewed by using journalctl or the ofm journal command.

Class OFMHandler A logging.Handler that stores the most recent logs for access by the server.
Class UvicornAccessFilter A logging filter to filter out "uvicorn.access" messages.
Function configure_logging Configure logging for the server while it is running.
Function retrieve_log Return logs since the server started, up to a maximum of 250 messages.
Function retrieve_log_from_file Return the full log from the file for downloading.
Constant OFM_HANDLER Undocumented
Constant OFM_LOG_FILE Undocumented
def configure_logging(log_folder): (source)

Configure logging for the server while it is running.

This modifies the root logger to have a rotating file handler and adds a custom handler that prints and stores all records except uvicorn.access logs.

It is important not to let Uvicorn override these settings.

def retrieve_log() -> PlainTextResponse: (source)

Return logs since the server started, up to a maximum of 250 messages.

This log is the one shown in the UI and on the logging page.

It does not include any of the uvicorn.access logs as these are emitted every time any API route is called.

All logs, including uvicorn.access are logged to the OFM_LOG_FILE (see above) this is the best place to get logs about crashes.

def retrieve_log_from_file() -> PlainTextResponse: (source)

Return the full log from the file for downloading.

Note this is read and then sent as otherwise it causes a RuntimeError if it is written to while sending through FileResponse.

OFM_HANDLER = (source)

Undocumented

Value
OFMHandler()
OFM_LOG_FILE = (source)

Undocumented

Value
None