You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Michael Han (JIRA)" <ji...@apache.org> on 2017/03/13 16:22:02 UTC

[jira] [Updated] (ZOOKEEPER-2088) Provide custom logging hook

     [ https://issues.apache.org/jira/browse/ZOOKEEPER-2088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Han updated ZOOKEEPER-2088:
-----------------------------------
    Fix Version/s:     (was: 3.5.3)
                   3.5.4

> Provide custom logging hook
> ---------------------------
>
>                 Key: ZOOKEEPER-2088
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2088
>             Project: ZooKeeper
>          Issue Type: Wish
>          Components: c client
>    Affects Versions: 3.4.6
>         Environment: Linux
>            Reporter: Jean-François SMIGIELSKI
>            Assignee: Jean-François SMIGIELSKI
>            Priority: Trivial
>              Labels: newbie
>             Fix For: 3.5.4, 3.6.0
>
>
> 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;



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)