[C-API, python-package] Add leveled logging callback to C API and Python bindings#7205
[C-API, python-package] Add leveled logging callback to C API and Python bindings#7205AnyCPU wants to merge 4 commits intolightgbm-org:masterfrom
Conversation
There was a problem hiding this comment.
Thanks for the PR. I'll review when I can. Some clarifying questions...
_ forcing bindings to reassemble them._
Could you link to examples where this is happening? I've asked you for that twice before, in these previous conversations:
Seeing those examples would help us to understand how these proposed changes help. We won't take on an expansion of the library's public API (and therefore complexity and maintenance burden) without a better understanding of the benefit.
Validation, unit, integration, and lifecycle tests for all four log levels;
I see only unit tests added in this PR. What do you mean by "integration" and "lifecyle" tests? Are those something you're planning to add but haven't yet?
take a look at python snippet above, that is taken from existing code in the python package. if you are interested in what exactly language bindings I'm working on? without reassembly, a naive binding will output something like: 2026/03/17 14:30:01 INFO [LightGBM] [Warning]
2026/03/17 14:30:01 INFO There are no meaningful features which satisfy the provided configuration
2026/03/17 14:30:01 INFO
2026/03/17 14:30:01 INFO [LightGBM] [Info]
2026/03/17 14:30:01 INFO Number of positive: 2, number of negative: 2
2026/03/17 14:30:01 INFO
2026/03/17 14:30:01 INFO [LightGBM] [Warning]
2026/03/17 14:30:01 INFO Stopped training because there are no more leaves that meet the split requirements
2026/03/17 14:30:01 INFO
happy to change wording if the terminology is confusing. |
|
Add leveled logging callback to C API and Python bindings
The existing LGBM_RegisterLogCallback sends log messages as raw const char* with no severity metadata.
Each log event arrives as three separate callback invocations (prefix, body, newline), forcing bindings to reassemble them.
The Python package works around this today:
I think this is fragile (relies on an empty-string sentinel to flush) and loses the log level: everything goes to logger.info() regardless of severity.
And I think that other language bindings should not have to replicate this pattern.
This MR adds LGBM_RegisterLogCallbackWithLevel, which delivers (int level, const char* msg): one call per event, no prefix, no trailing newline.
CHANGES
C++ / C API
PYTHON
TESTS