Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-2088

Provide custom logging hook

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Open
    • Trivial
    • Resolution: Unresolved
    • 3.4.6
    • None
    • c client
    • Linux

    Description

      Hello, proud Zookeeper maintainers!

      I incoporated the zookeeper C client API in a quite large code base. The result is fine, everything works as expected but the logs. Our code already manages its log traces via one API, the GLib-2.0 logging features. The current "FILE*" based logging of the C client is not suitable for us.

      I propose to integrate a minimal change that would allows me to plug ZK's output on any other : a simple logging hook. I pasted below the patch I propose.

      What do you think about ?

      diff -r -U3 zookeeper-3.4.6/src/c/include/zookeeper_log.h zookeeper-3.4.6-new/src/c/include/zookeeper_log.h
      — zookeeper-3.4.6/src/c/include/zookeeper_log.h 2014-02-20 11:14:08.000000000 +0100
      +++ zookeeper-3.4.6-new/src/c/include/zookeeper_log.h 2014-11-24 13:36:21.088124921 +0100
      @@ -44,6 +44,10 @@

      FILE* getLogStream();

      +typedef void (zk_hook_log) (ZooLogLevel, int, const char*, const char *);
      +
      +void zoo_set_log_hook (zk_hook_log *hook);
      +
      #ifdef __cplusplus
      }
      #endif

      diff -r -U3 zookeeper-3.4.6/src/c/src/zk_log.c zookeeper-3.4.6-new/src/c/src/zk_log.c
      — zookeeper-3.4.6/src/c/src/zk_log.c 2014-02-20 11:14:09.000000000 +0100
      +++ zookeeper-3.4.6-new/src/c/src/zk_log.c 2014-11-24 14:28:46.151503385 +0100
      @@ -122,9 +122,17 @@
      return now_str;
      }

      +static zk_hook_log *log_hook = NULL;
      +void zoo_set_log_hook (zk_hook_log *hook)
      +

      { + log_hook = hook; +}

      +
      void log_message(ZooLogLevel curLevel,int line,const char* funcName,
      const char* message)
      {
      + if (log_hook) return (*log_hook)(curLevel, line, funcName, message);
      +
      static const char* dbgLevelStr[]=

      {"ZOO_INVALID","ZOO_ERROR","ZOO_WARN", "ZOO_INFO","ZOO_DEBUG"}

      ;
      static pid_t pid=0;

      Attachments

        Activity

          People

            jf.smigielski Jean-François SMIGIELSKI
            jf.smigielski Jean-François SMIGIELSKI
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: