|
4 | 4 | #include <ruby/thread.h> |
5 | 5 |
|
6 | 6 | #include "client.hpp" |
| 7 | +#include "logger.hpp" |
7 | 8 | #include "util.hpp" |
8 | 9 |
|
9 | 10 | namespace pulsar_rb { |
@@ -55,6 +56,25 @@ void ClientConfiguration::setLogConfFilePath(const std::string& path) { |
55 | 56 | _config.setLogConfFilePath(path); |
56 | 57 | } |
57 | 58 |
|
| 59 | +void ClientConfiguration::setSilentLogging(bool enable) { |
| 60 | + // The logger can only be set once, so if it's already on we cannot disable it. |
| 61 | + if (silentLogging) { |
| 62 | + if (!enable) { |
| 63 | + throw Rice::Exception(rb_eArgError, "silent_logging can only be set once"); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + if (enable) { |
| 68 | + silentLogging = true; |
| 69 | + std::unique_ptr<LoggerFactory> loggerFactory = SilentLoggerFactory::create(); |
| 70 | + _config.setLogger(loggerFactory.release()); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +bool ClientConfiguration::getSilentLogging() { |
| 75 | + return silentLogging; |
| 76 | +} |
| 77 | + |
58 | 78 | bool ClientConfiguration::isUseTls() { |
59 | 79 | return _config.isUseTls(); |
60 | 80 | } |
@@ -175,6 +195,8 @@ void bind_client(Module& module) { |
175 | 195 | .define_method("concurrent_lookup_requests=", &pulsar_rb::ClientConfiguration::setConcurrentLookupRequest) |
176 | 196 | .define_method("log_conf_file_path", &pulsar_rb::ClientConfiguration::getLogConfFilePath) |
177 | 197 | .define_method("log_conf_file_path=", &pulsar_rb::ClientConfiguration::setLogConfFilePath) |
| 198 | + .define_method("silent_logging?", &pulsar_rb::ClientConfiguration::getSilentLogging) |
| 199 | + .define_method("silent_logging=", &pulsar_rb::ClientConfiguration::setSilentLogging) |
178 | 200 | .define_method("use_tls?", &pulsar_rb::ClientConfiguration::isUseTls) |
179 | 201 | .define_method("use_tls=", &pulsar_rb::ClientConfiguration::setUseTls) |
180 | 202 | .define_method("tls_trust_certs_file_path", &pulsar_rb::ClientConfiguration::getTlsTrustCertsFilePath) |
|
0 commit comments