[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 5 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. |
|
I've now asked many times for evidence of this like links to other LightGBM bindings and links to your own code, and you've declined to provide them. You haven't convinced me of the strong claim that "all" bindings "need" the functionality you're proposing. It seems more like some project you are working on would find it convenient to have this functionality. That's totally fine, but it does change the way we prioritize. I personally am not planning to engage any more with this PR, but I also will not get in the way if some other maintainer here wants to work with you on moving it forward. |
Removing my blocking review to get out of the way.
the C API defines a public interface. together with certain C++ implementation details, it establishes a data contract: anyone interested in using the C API directly or creating language bindings has to do something like LightGBM/python-package/lightgbm/basic.py Line 265 in 648ae78 for my use case, it is important to collect logs and route them into a monitoring system. that is why this PR exists. it provides:
if someone is already using the existing logger API, they can simply continue using it: there are no breaking changes. |
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