Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ For the supported Pulsar features, see [Client Feature Matrix](https://pulsar.ap

For how to use APIs to publish and consume messages, see [examples](https://github.com/apache/pulsar-client-cpp/tree/main/examples).

## Custom logger lifetime

The C++ client supports one custom logger factory per process. A logger configured
through `ClientConfiguration::setLogger` or the C API logger functions is shared
by all clients in the same process and is not scoped to an individual client
instance. Set the custom logger before creating clients, and do not expect
different clients to have independent log handlers.

If an application or language binding exposes logger callbacks, the callback and
its context must remain valid until all Pulsar clients are closed and no
background thread can emit client logs. Avoid tying the callback lifetime to a
single client when multiple clients can exist in the process.

## Import the library into your project

### CMake with vcpkg integration
Expand Down
15 changes: 11 additions & 4 deletions include/pulsar/ClientConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,22 @@ class PULSAR_PUBLIC ClientConfiguration {
int getMaxBackoffIntervalMs() const;

/**
* Configure a custom logger backend to route of Pulsar client library
* Configure a custom logger backend to route Pulsar client library logs
* to a different logger implementation.
*
* By default, log messages are printed on standard output.
*
* When passed in, the configuration takes ownership of the loggerFactory object.
* The logger factory can only be set once per process. Any subsequent calls to
* set the logger factory will have no effect, though the logger factory object
* will be cleaned up.
* The logger factory is process-wide and is not scoped to a Client instance.
* It can only be set once per process. Any subsequent calls to set the logger
* factory will have no effect, though the logger factory object will be
* cleaned up.
*
* Applications and language bindings that use callback-based logger factories
* should set the logger before creating clients and ensure callback state
* outlives all Pulsar clients and background threads that can emit logs.
* Avoid using per-client callback objects that can be destroyed while another
* client in the same process is still running.
*/
ClientConfiguration& setLogger(LoggerFactory* loggerFactory);

Expand Down
16 changes: 16 additions & 0 deletions include/pulsar/c/client_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,25 @@ PULSAR_PUBLIC void pulsar_client_configuration_set_concurrent_lookup_request(
PULSAR_PUBLIC int pulsar_client_configuration_get_concurrent_lookup_request(
pulsar_client_configuration_t *conf);

/**
* Configure a custom logger for Pulsar client library logs.
*
* The logger is process-wide and is not scoped to a pulsar_client_t instance.
* It can only be set once per process. Applications and language bindings
* should set the logger before creating clients and ensure the logger callback
* context outlives all Pulsar clients and background threads that can emit logs.
*/
PULSAR_PUBLIC void pulsar_client_configuration_set_logger(pulsar_client_configuration_t *conf,
pulsar_logger logger, void *ctx);

/**
* Configure a custom logger for Pulsar client library logs.
*
* The logger is process-wide and is not scoped to a pulsar_client_t instance.
* It can only be set once per process. Applications and language bindings
* should set the logger before creating clients and ensure the logger callback
* context outlives all Pulsar clients and background threads that can emit logs.
*/
PULSAR_PUBLIC void pulsar_client_configuration_set_logger_t(pulsar_client_configuration_t *conf,
pulsar_logger_t logger);

Expand Down
Loading