Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Add C++ single file logger factory #10712

Merged
merged 5 commits into from
May 29, 2021

Conversation

BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented May 26, 2021

Motivation

Some users are confused about how to customize the logger in C++ client, while they don't want to build their own cpp library with log4cxx support and change the log4cxx.conf file.

Modifications

  • Add a FileLoggerFactory class to support writing logs to a single file.
  • Rename the existed SimpleLoggerFactory to ConsoleLoggerFactory to differ it with FileLoggerFactory.
  • Use PImpl idiom to hide implementations for these two LoggerFactory classes.
  • Add PULSAR_PUBLIC to logger factory classes so that they can be exported.
  • Provide an example program that writes logs to a single file.
  • Change other examples' topic name to v2 format instead of the old v1 topic format.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage. If you ran the SampleFileLogger program in your local env without any pulsar server, a pulsar-client-cpp.log would be created and it contains the content like following.

Wed May 26 15:34:03 2021 INFO [0x10fde8e00] ConnectionPool:84 Created connection for pulsar://localhost:6650
Wed May 26 15:34:03 2021 ERROR [0x700002a2c000] ClientConnection:422 [<none> -> pulsar://localhost:6650] Failed to establish connection: Connection refused
Wed May 26 15:34:03 2021 INFO [0x700002a2c000] ClientConnection:1446 [<none> -> pulsar://localhost:6650] Connection closed
Wed May 26 15:34:03 2021 ERROR [0x700002a2c000] ClientImpl:181 Error Checking/Getting Partition Metadata while creating producer on persistent://public/default/my-topic -- ConnectError
Wed May 26 15:34:03 2021 INFO [0x700002a2c000] ClientConnection:261 [<none> -> pulsar://localhost:6650] Destroyed connection
Wed May 26 15:34:03 2021 INFO [0x10fde8e00] ClientImpl:483 Closing Pulsar client

@BewareMyPower BewareMyPower changed the title [C++] Add SampleFileLogger C++ example [C++] Add C++ example for customizing the logger factory May 26, 2021
@BewareMyPower BewareMyPower self-assigned this May 26, 2021
@BewareMyPower BewareMyPower changed the title [C++] Add C++ example for customizing the logger factory [WIP][C++] Add C++ example for customizing the logger factory May 26, 2021
@BewareMyPower BewareMyPower changed the title [WIP][C++] Add C++ example for customizing the logger factory [C++] Add C++ single file logger factory May 27, 2021
@BewareMyPower
Copy link
Contributor Author

It looks like there's something wrong with the build on CentOS 7, I'll take a look.

@BewareMyPower
Copy link
Contributor Author

@merlimat Done. PTAL again

@merlimat merlimat added this to the 2.8.0 milestone May 28, 2021
@merlimat merlimat added the type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages label May 28, 2021
@merlimat merlimat merged commit 1ab2bfc into apache:master May 29, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/add-cpp-examples branch May 31, 2021 02:01
wangjialing218 pushed a commit to wangjialing218/pulsar that referenced this pull request May 31, 2021
* Add SampleFileLogger C++ example

* Expose SingleFileLoggerFactory as the public interface

* Make logger factory public

* Change logger factory's name

* Use PImpl idiom for LoggerFactory classes
yangl pushed a commit to yangl/pulsar that referenced this pull request Jun 23, 2021
* Add SampleFileLogger C++ example

* Expose SingleFileLoggerFactory as the public interface

* Make logger factory public

* Change logger factory's name

* Use PImpl idiom for LoggerFactory classes
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
* Add SampleFileLogger C++ example

* Expose SingleFileLoggerFactory as the public interface

* Make logger factory public

* Change logger factory's name

* Use PImpl idiom for LoggerFactory classes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants