The C API supports setting the log level.#158
Conversation
|
Not related to this PR, I found the |
Thanks for the reminder. I open a new PR #159 fix it. |
There was a problem hiding this comment.
I prefer to change the definition of pulsar_logger and use the new function to deprecate the old function to set the logger:
// NOTE: you need to include <stdbool.h> to have bool in C
typedef struct pulsar_logger_t {
void (*log)(pulsar_logger_level_t level, const char *file, int line, const char *message, void *ctx);
bool (*is_enabled)(pulsar_logger_level_t level);
} pulsar_logger_t;
/**
* Deprecated. Use `pulsar_client_configuration_set_logger_t` instead.
*/
PULSAR_PUBLIC void pulsar_client_configuration_set_logger(pulsar_client_configuration_t *conf,
pulsar_logger logger, void *ctx);
PULSAR_PUBLIC void pulsar_client_configuration_set_logger_t(pulsar_client_configuration_t *conf,
pulsar_logger_t logger, void *ctx);This abstraction will be more like the C++'s Logger.
|
The design might not be good, I think how to configure the logger might need more considerations. It's better to make the configuration more flexible. |
|
I will merge this PR for now. It's only included in the next 3.2.0 release. If I have a better idea, I will open a PR to remove the new API in this PR. |
### Motivation The current `pulsar_client_configuration_set_logger` API can only configure the `Logger::log` method, but the` Logger::isEnabled` method cannot be configured via C API. apache#158 added a `pulsar_client_configuration_set_logger_and_level` function to configure a log level, but it's not flexible. For example, the log level might be modified dynamically (though it's a complicated case). ### Modifications Add a `pulsar_logger_t` struct and the related `pulsar_client_configuration_set_logger_t` function to configure it as the C logger API. The `is_enabled` and `log` fields of the struct are the responding methods of the `isEnabled` and `log` methods in C++ `Logger`. Then add a `LogContext` example in `SampleCustomLoggerCApi.c` to print logs to a file or standard output. Eliminate the `pulsar_client_configuration_set_logger_and_level` function.
### Motivation The current `pulsar_client_configuration_set_logger` API can only configure the `Logger::log` method, but the` Logger::isEnabled` method cannot be configured via C API. apache#158 added a `pulsar_client_configuration_set_logger_and_level` function to configure a log level, but it's not flexible. For example, the log level might be modified dynamically (though it's a complicated case). ### Modifications Add a `pulsar_logger_t` struct and the related `pulsar_client_configuration_set_logger_t` function to configure it as the C logger API. The `is_enabled` and `log` fields of the struct are the responding methods of the `isEnabled` and `log` methods in C++ `Logger`. Then add a `LogContext` example in `SampleCustomLoggerCApi.c` to print logs to a file or standard output. Eliminate the `pulsar_client_configuration_set_logger_and_level` function.
### Motivation The current `pulsar_client_configuration_set_logger` API can only configure the `Logger::log` method, but the` Logger::isEnabled` method cannot be configured via C API. #158 added a `pulsar_client_configuration_set_logger_and_level` function to configure a log level, but it's not flexible. For example, the log level might be modified dynamically (though it's a complicated case). ### Modifications Add a `pulsar_logger_t` struct and the related `pulsar_client_configuration_set_logger_t` function to configure it as the C logger API. The `is_enabled` and `log` fields of the struct are the responding methods of the `isEnabled` and `log` methods in C++ `Logger`. Then add a `LogContext` example in `SampleCustomLoggerCApi.c` to print logs to a file or standard output. Eliminate the `pulsar_client_configuration_set_logger_and_level` function.
Motivation
#137
Modifications
pulsar_client_configuration_set_logger_and_levelto support set the log level.Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)