Logging
LogCategory
Bases: IntEnum
Logging categories for kernel messages.
These categories allow fine-grained control over which types of log messages are enabled. Categories can be individually enabled or disabled.
Source code in pbk/log.py
LogLevel
Bases: IntEnum
Log severity levels.
These levels control the minimum severity of messages that will be logged. Setting a level filters out messages below that severity.
Note
The TRACE level from bitcoinkernel is not exposed, as it is not natively supported by Python's logging library.
Source code in pbk/log.py
LoggingOptions
Bases: btck_LoggingOptions
Configuration options for log message formatting.
These options control which metadata is included in log messages, such as timestamps, thread names, and source locations.
Source code in pbk/log.py
always_print_category_levels
instance-attribute
__init__
__init__(log_timestamps: bool = True, log_time_micros: bool = False, log_threadnames: bool = False, log_sourcelocations: bool = False, always_print_category_levels: bool = False)
Create logging format options.
| PARAMETER | DESCRIPTION |
|---|---|
log_timestamps
|
If True, prepend a timestamp to log messages.
TYPE:
|
log_time_micros
|
If True, use microsecond precision for timestamps.
TYPE:
|
log_threadnames
|
If True, prepend the thread name to log messages.
TYPE:
|
log_sourcelocations
|
If True, prepend the source file location to log messages.
TYPE:
|
always_print_category_levels
|
If True, prepend the category and level to log messages.
TYPE:
|
Source code in pbk/log.py
logging_set_options
Set formatting options for the global internal logger.
This changes global settings that affect all existing LoggingConnection instances. The changes take effect immediately.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
Logging format options to apply.
TYPE:
|
Source code in pbk/log.py
set_log_level_category
Set the minimum log level for a category.
This changes the minimum severity of messages that will be logged for the specified category. Affects all existing LoggingConnection instances.
Note
This does not enable categories. Use enable_log_category() to start
logging from a category. If LogCategory.ALL is chosen, sets both the
global fallback log level and the level for the ALL category itself.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The log category to configure.
TYPE:
|
level
|
The minimum log level for this category.
TYPE:
|
Source code in pbk/log.py
enable_log_category
Enable logging for a category.
Once enabled, log messages from this category will be passed to all LoggingConnection callbacks. If LogCategory.ALL is chosen, all categories will be enabled.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The log category to enable.
TYPE:
|
Source code in pbk/log.py
disable_log_category
Disable logging for a category.
Once disabled, log messages from this category will no longer be passed to LoggingConnection callbacks. If LogCategory.ALL is chosen, all categories will be disabled.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The log category to disable.
TYPE:
|
Source code in pbk/log.py
LoggingConnection
Bases: KernelOpaquePtr
Connection that receives kernel log messages via a callback.
A logging connection invokes a callback function for every log message produced by the kernel. The connection can be destroyed to stop receiving messages. Messages logged before the first connection is created are buffered (up to 1MB) and delivered when the connection is established.
Source code in pbk/log.py
__init__
Create a logging connection with a callback.
| PARAMETER | DESCRIPTION |
|---|---|
cb
|
Callback function that accepts a single string parameter (the log message) and returns None.
TYPE:
|
user_data
|
Optional user data to associate with the connection.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the callback doesn't have the correct signature. |
RuntimeError
|
If the C constructor fails (propagated from base class). |
Source code in pbk/log.py
KernelLogViewer
Integration between bitcoinkernel logging and Python's logging module.
KernelLogViewer bridges bitcoinkernel's logging system with Python's standard logging module. It creates a LoggingConnection that parses kernel log messages and forwards them to a Python Logger instance.
Messages are organized by category, with each category getting its own child logger. For example, VALIDATION messages go to a logger named "bitcoinkernel.VALIDATION".
Note
To see debug messages, both the kernel category must be enabled
(via the categories parameter) and the Python logger level must
be set to DEBUG or lower.
Source code in pbk/log.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
__init__
Create a log viewer that forwards kernel logs to Python logging.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name for the root logger. Defaults to "bitcoinkernel".
TYPE:
|
categories
|
List of log categories to enable. If None or empty, no categories are enabled by default.
TYPE:
|
Source code in pbk/log.py
getLogger
Get the Python logger for a specific category.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The log category to get a logger for. If None, returns the root logger.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Logger
|
A logging.Logger instance for the specified category. |
Source code in pbk/log.py
temporary_categories
Context manager to temporarily enable log categories.
Enables the specified categories for the duration of the context, then disables them when exiting. Categories that were enabled during initialization remain enabled.
| PARAMETER | DESCRIPTION |
|---|---|
categories
|
List of categories to temporarily enable.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
None
|
None |