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?

Community
  • 1
  • 1
BAE
  • 8,550
  • 22
  • 88
  • 171

2 Answers2

1
FILE* outfile =  fopen ("nul", "w");
  zoo_set_log_stream(outfile);
Simal Haneef
  • 179
  • 5
  • 1
    this is windows on linux you can use /dev/null – Simal Haneef Aug 17 '16 at 07:37
  • you could write something like this : zoo_set_log_stream(fopen("NULL", "w")); – serup Nov 29 '16 at 13:10
  • `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 ... – Simal Haneef Apr 07 '17 at 05:49
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.

BAE
  • 8,550
  • 22
  • 88
  • 171
  • 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 = 4` – serup Nov 29 '16 at 12:58
  • @serup, could you give more details? I used the function long ago.... But it works. – BAE Nov 29 '16 at 14:42
  • 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"));` – serup Nov 30 '16 at 08:47
  • @serup My answer was a little confusing. `Use zoo_set_debug_level()` means `zoo_set_debug_level()`, 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. – BAE Nov 30 '16 at 14:49
  • what is (ZooLogLevel)0 if it does not result in one of the valid arguments, then it will fail – serup Dec 01 '16 at 08:54
  • 1
    @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. – BAE Dec 01 '16 at 14:38