logging_helper.aibs¶
AibsLogServerHandlerSettings ¶
Bases: ServiceSettings
Settings for the AIBS log server handler.
Handler that sends log records to a remote AIBS log server over HTTP.
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: Type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> Tuple[PydanticBaseSettingsSource, ...]
Customizes the settings sources to include the safe YAML settings source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_cls
|
Type[BaseSettings]
|
The settings class |
required |
init_settings
|
PydanticBaseSettingsSource
|
The initial settings source |
required |
env_settings
|
PydanticBaseSettingsSource
|
The environment settings source |
required |
dotenv_settings
|
PydanticBaseSettingsSource
|
The dotenv settings source |
required |
file_secret_settings
|
PydanticBaseSettingsSource
|
The file secret settings source |
required |
Returns:
| Type | Description |
|---|---|
Tuple[PydanticBaseSettingsSource, ...]
|
Tuple[PydanticBaseSettingsSource, ...]: A tuple of settings sources |
Source code in src/clabe/services.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
AibsLogServerHandler ¶
AibsLogServerHandler(
settings: AibsLogServerHandlerSettings, *args, **kwargs
)
Bases: SocketHandler
A custom logging handler that sends log records to the AIBS log server.
Extends the standard SocketHandler to include project-specific metadata in the log records before sending them to the log server.
Initializes the AIBS log server handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
AibsLogServerHandlerSettings
|
Configuration for the handler |
required |
*args
|
Additional arguments to pass to the SocketHandler |
()
|
|
**kwargs
|
Additional keyword arguments to pass to the SocketHandler |
{}
|
Source code in src/clabe/logging_helper/aibs.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
emit ¶
emit(record: LogRecord) -> None
Emits a log record with project-specific metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
The log record to emit |
required |
Source code in src/clabe/logging_helper/aibs.py
84 85 86 87 88 89 90 91 92 93 94 95 96 | |
add_handler ¶
add_handler(
logger: TLogger, settings: AibsLogServerHandlerSettings
) -> TLogger
Adds an AIBS log server handler to the logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
TLogger
|
The logger to add the handler to. |
required |
settings
|
AibsLogServerHandlerSettings
|
AibsLogServerHandlerSettings containing configuration options |
required |
Returns:
| Type | Description |
|---|---|
TLogger
|
The logger with the added handler. |
Examples:
import logging
from clabe.logging_helper.aibs import add_handler, AibsLogServerHandlerSettings
# Create a logger
logger = logging.getLogger('my_logger')
logger.setLevel(logging.INFO)
# Add the AIBS log server handler with default ERROR level
settings = AibsLogServerHandlerSettings(
project_name='my_project',
version='1.0.0',
host='localhost',
port=5000
)
logger = add_handler(logger, settings)
# Add handler with custom level
settings = AibsLogServerHandlerSettings(
project_name='my_project',
version='1.0.0',
host='localhost',
port=5000,
level=logging.WARNING
)
logger = add_handler(logger, settings)
Source code in src/clabe/logging_helper/aibs.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
attach_to_launcher ¶
attach_to_launcher(
launcher: Launcher,
settings: AibsLogServerHandlerSettings,
) -> Launcher
Attaches an AIBS log server handler to a launcher instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
launcher
|
Launcher
|
The launcher instance to attach the handler to. |
required |
settings
|
AibsLogServerHandlerSettings
|
AibsLogServerHandlerSettings containing configuration options |
required |
Returns:
| Type | Description |
|---|---|
Launcher
|
The launcher instance with the attached handler. |
Examples:
import logging
from clabe.launcher import Launcher
from clabe.logging_helper.aibs import attach_to_launcher, AibsLogServerHandlerSettings
# Initialize the launcher
launcher = MyLauncher(...) # Replace with your custom launcher class
# Attach the AIBS log server handler with default ERROR level
settings = AibsLogServerHandlerSettings(
project_name='my_launcher_project',
version='1.0.0',
host='localhost',
port=5000
)
launcher = attach_to_launcher(launcher, settings)
# Attach handler with custom level
settings = AibsLogServerHandlerSettings(
project_name='my_launcher_project',
version='1.0.0',
host='localhost',
port=5000,
level=logging.WARNING
)
launcher = attach_to_launcher(launcher, settings)
Source code in src/clabe/logging_helper/aibs.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |