Logging System
The RxInfer Server uses a logging system that divides logs by functional groups and stores them in separate files.
Configuration
For logging configuration options, see Logging Configuration in the main configuration documentation.
Architecture
The logging functionality is encapsulated in the Logging
module (src/logging.jl
), which:
- Uses a
TeeLogger
to output logs to multiple destinations simultaneously - Groups logs by their functional component
- Maintains separate log files for each tag/group (e.g.,
Server.log
,Authentification.log
)
Usage
The Logging.with_logger
function is the primary API:
Logging.with_logger() do
@info "This message will be logged to both terminal and files"
end
Log Groups
Log groups are automatically derived from the file basename. For example:
- Messages from
src/tags/Server.jl
belong to the:Server
group - Messages from
src/tags/Authentification.jl
belong to the:Authentification
group - Messages from
src/tags/Models.jl
belong to the:Models
group
The system routes logs to the appropriate files based on these groups without requiring explicit group specification.
API Reference
RxInferServer.Logging.with_logger
— Functionwith_logger(f)
Sets up the logging system and executes the provided function with the configured logger. Creates a TeeLogger that writes to:
- Terminal with human-readable formatting
- A main log file (.log) with all messages
- Separate files for each functional group (Server.log, Authentification.log, etc.)
- A debug log file (debug.log) if debug logging is enabled, see
RxInferServer.Logging.RXINFER_SERVER_ENABLE_DEBUG_LOGGING
Arguments
f
: The function to execute with the configured logger
Examples
Logging.with_logger() do
@info "This message will be logged to both terminal and files"
end
Returns
- The return value of the provided function
RxInferServer.Logging.with_simple_logger
— Functionwith_simple_logger(f, io::IO)
Sets up the logging system and executes the provided function with the configured logger. Creates a SimpleLogger that writes to the specified IO stream.
Arguments
f
: The function to execute with the configured loggerio
: The IO stream to write the logs to
Returns
- The return value of the provided function
RxInferServer.Logging.filter_by_group
— Functionfilter_by_group(group)
Creates a logger filter function that only allows log messages with the specified group tag. Used to separate logs into different files by their functionality/module.
Arguments
group
: The symbol representing a log group (e.g.,:Server
,:Authentification
)
Returns
- A function that takes a logger and returns an EarlyFilteredLogger that filters by the specified group
RxInferServer.Logging.filter_by_module
— Functionfilter_by_module(_module)
Creates a logger filter function that only allows log messages from the specified module. Used to separate logs by their source module. Uses occursin
to match the module name.
Arguments
_module
: The module name to filter by (e.g.,"RxInferServer"
), must be a string
Returns
- A function that takes a logger and returns an EarlyFilteredLogger that filters by the specified module
RxInferServer.Logging.filter_by_level
— Functionfilter_by_level(level_range)
Creates a logger filter function that only allows log messages within the specified range of log levels. Used to separate logs by their severity level.
Arguments
level_range
: A range of log levels to include
Returns
- A function that takes a logger and returns an EarlyFilteredLogger that filters by the specified level range
Adding New OpenAPI Tags
When adding new tags to the OpenAPI schema:
- Create a new file in the
src/tags/
directory (e.g.,NewTag.jl
) - Add a corresponding logger in the
Logging.with_logger
function:
# In src/logging.jl:
MiniLoggers.MiniLogger(; io = joinpath(RXINFER_SERVER_LOGS_LOCATION, "NewTag.log"), kwargs_logger...) |> filter_by_group(:NewTag)
This ensures logs from the new tag will be properly captured in a dedicated log file.