how to turn off zookeeper log info?
Asked Answered
S

2

2

I am using zookeeper c client library. When I run my program, it will output ZOO_INFO to console. Part of log messages looks like:

2015-03-26 20:08:22,115:15978(0x7f83a1fbc740):ZOO_INFO@log_env@712: Client environment:zookeeper.version=zookeeper C client 3.4.6

2015-03-26 20:08:22,115:15978(0x7f83a1fbc740):ZOO_INFO@log_env@716: Client environment:host.name=myhost

2015-03-26 20:08:22,115:15978(0x7f83a1fbc740):ZOO_INFO@log_env@723: Client environment:os.name=Linux

2015-03-26 20:08:22,115:15978(0x7f83a1fbc740):ZOO_INFO@log_env@724: Client environment:os.arch=3.2.0-34-generic

2015-03-26 20:08:22,115:15978(0x7f83a1fbc740):ZOO_INFO@log_env@725: Client environment:os.version=#53-Ubuntu SMP Thu Nov 15 10:48:16 UTC 2012

2015-03-26 20:08:22,115:15978(0x7f83a1fbc740):ZOO_INFO@log_env@733: Client environment:user.name=myname

...

I can use zoo_set_log_stream(m_zklog); to output these messages to some log files. But I prefer to turn off all the log messages. I also tried zoo_set_debug_level( ZOO_LOG_LEVEL_ERROR );. But it can not turn off all the messages. Any ideas?

Sitra answered 26/3, 2015 at 20:18 Comment(0)
S
0

Use C API zoo_set_debug_level() (e.g. zoo_set_debug_level((ZooLogLevel)0)). But call this function before zookeeper_init(), otherwise, it will fail.

Sitra answered 14/4, 2015 at 14:39 Comment(6)
the only valid arguments are following : # only used by the C extension ZOO_LOG_LEVEL_ERROR = 1 ZOO_LOG_LEVEL_WARN = 2 ZOO_LOG_LEVEL_INFO = 3 ZOO_LOG_LEVEL_DEBUG = 4Adventurism
@serup, could you give more details? I used the function long ago.... But it works.Sitra
I tried without parameters on a ubuntu 16.04lts build and it would not compile - so perhaps things have changed - I ended up using this instead : zoo_set_log_stream(fopen("NULL", "w"));Adventurism
@Adventurism My answer was a little confusing. Use zoo_set_debug_level() means zoo_set_debug_level(<parameters>), e.g. zoo_set_debug_level((ZooLogLevel)0). The point of my answer was that the function should be called before zookeeper_init(), otherwise it cannot work. My answer updated. Sorry for the confusion.Sitra
what is (ZooLogLevel)0 if it does not result in one of the valid arguments, then it will failAdventurism
@serup, I just gave an example that zoo_set_debug_level() has input parameter. We are using clients of different version. Just add the parameter according to your doc. The above example works fine in our codes, and I did not give all contexts, which are not important to my points.Sitra
F
1
FILE* outfile =  fopen ("nul", "w");
  zoo_set_log_stream(outfile);
Farlie answered 17/8, 2016 at 7:37 Comment(3)
this is windows on linux you can use /dev/nullFarlie
you could write something like this : zoo_set_log_stream(fopen("NULL", "w"));Adventurism
if (!m_zkLogFile) { zoo_set_debug_level( (ZooLogLevel)0); #ifdef WIN32_OS m_zkLogFile = fopen ("nul", "w"); #else m_zkLogFile = fopen ("/dev/null", "w"); #endif zoo_set_log_stream(m_zkLogFile); } This works ...Farlie
S
0

Use C API zoo_set_debug_level() (e.g. zoo_set_debug_level((ZooLogLevel)0)). But call this function before zookeeper_init(), otherwise, it will fail.

Sitra answered 14/4, 2015 at 14:39 Comment(6)
the only valid arguments are following : # only used by the C extension ZOO_LOG_LEVEL_ERROR = 1 ZOO_LOG_LEVEL_WARN = 2 ZOO_LOG_LEVEL_INFO = 3 ZOO_LOG_LEVEL_DEBUG = 4Adventurism
@serup, could you give more details? I used the function long ago.... But it works.Sitra
I tried without parameters on a ubuntu 16.04lts build and it would not compile - so perhaps things have changed - I ended up using this instead : zoo_set_log_stream(fopen("NULL", "w"));Adventurism
@Adventurism My answer was a little confusing. Use zoo_set_debug_level() means zoo_set_debug_level(<parameters>), e.g. zoo_set_debug_level((ZooLogLevel)0). The point of my answer was that the function should be called before zookeeper_init(), otherwise it cannot work. My answer updated. Sorry for the confusion.Sitra
what is (ZooLogLevel)0 if it does not result in one of the valid arguments, then it will failAdventurism
@serup, I just gave an example that zoo_set_debug_level() has input parameter. We are using clients of different version. Just add the parameter according to your doc. The above example works fine in our codes, and I did not give all contexts, which are not important to my points.Sitra

© 2022 - 2024 — McMap. All rights reserved.