Skip to content

Comments

[feat] Add pulsar_logger_t as the configurable C logger#162

Merged
BewareMyPower merged 1 commit intoapache:mainfrom
BewareMyPower:bewaremypower/c-logger
Jan 4, 2023
Merged

[feat] Add pulsar_logger_t as the configurable C logger#162
BewareMyPower merged 1 commit intoapache:mainfrom
BewareMyPower:bewaremypower/c-logger

Conversation

@BewareMyPower
Copy link
Contributor

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.

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)

### 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.
@BewareMyPower BewareMyPower added the enhancement New feature or request label Dec 29, 2022
@BewareMyPower BewareMyPower added this to the 3.2.0 milestone Dec 29, 2022
@BewareMyPower BewareMyPower self-assigned this Dec 29, 2022
@BewareMyPower
Copy link
Contributor Author

@shibd @RobertIndie I added a more flexible interface to configure the C logger, so I removed the function added in the previous PR (#158). The PR also documents and shows to use the ctx, which is now a field of pulsar_logger_t.

@BewareMyPower BewareMyPower merged commit 8990b93 into apache:main Jan 4, 2023
@BewareMyPower BewareMyPower deleted the bewaremypower/c-logger branch January 4, 2023 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants