zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1516123 - in /zookeeper/trunk: CHANGES.txt src/c/src/mt_adaptor.c src/c/src/zk_log.c
Date Wed, 21 Aug 2013 09:40:42 GMT
Author: fpj
Date: Wed Aug 21 09:40:42 2013
New Revision: 1516123

URL: http://svn.apache.org/r1516123
Log:
ZOOKEEPER-1400. Allow logging via callback instead of raw FILE pointer (michi via fpj)


Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/c/src/mt_adaptor.c
    zookeeper/trunk/src/c/src/zk_log.c

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1516123&r1=1516122&r2=1516123&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Wed Aug 21 09:40:42 2013
@@ -545,6 +545,8 @@ IMPROVEMENTS:
 
   ZOOKEEPER-1413. Use on-disk transaction log for learner sync up (thawan)
 
+  ZOOKEEPER-1400. Allow logging via callback instead of raw FILE pointer (michi via fpj)
+
 Release 3.4.0 - 
 
 Non-backward compatible changes:

Modified: zookeeper/trunk/src/c/src/mt_adaptor.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/mt_adaptor.c?rev=1516123&r1=1516122&r2=1516123&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/mt_adaptor.c (original)
+++ zookeeper/trunk/src/c/src/mt_adaptor.c Wed Aug 21 09:40:42 2013
@@ -114,7 +114,7 @@ int process_async(int outstanding_sync)
 unsigned __stdcall do_io( void * );
 unsigned __stdcall do_completion( void * );
 
-int handle_error(SOCKET sock, char* message)
+int handle_error(zhandle_t* zh, SOCKET sock, char* message)
 {
        LOG_ERROR(LOGCALLBACK(zh), "%s. %d",message, WSAGetLastError());
        closesocket (sock);
@@ -122,7 +122,7 @@ int handle_error(SOCKET sock, char* mess
 }
 
 //--create socket pair for interupting selects.
-int create_socket_pair(SOCKET fds[2]) 
+int create_socket_pair(zhandle_t* zh, SOCKET fds[2]) 
 { 
     struct sockaddr_in inaddr; 
     struct sockaddr addr; 
@@ -141,23 +141,23 @@ int create_socket_pair(SOCKET fds[2]) 
     inaddr.sin_port = 0; //--system assigns the port
 
     if ( setsockopt(lst,SOL_SOCKET,SO_REUSEADDR,(char*)&yes,sizeof(yes)) == SOCKET_ERROR
 ) {
-       return handle_error(lst,"Error trying to set socket option.");          
+       return handle_error(zh, lst,"Error trying to set socket option.");          
     }  
     if (bind(lst,(struct sockaddr *)&inaddr,sizeof(inaddr)) == SOCKET_ERROR){
-       return handle_error(lst,"Error trying to bind socket.");                
+       return handle_error(zh, lst,"Error trying to bind socket.");                
     }
     if (listen(lst,1) == SOCKET_ERROR){
-       return handle_error(lst,"Error trying to listen on socket.");
+       return handle_error(zh, lst,"Error trying to listen on socket.");
     }
     len=sizeof(inaddr); 
     getsockname(lst, &addr,&len); 
     fds[0]=socket(AF_INET, SOCK_STREAM,0); 
     if (connect(fds[0],&addr,len) == SOCKET_ERROR){
-       return handle_error(lst, "Error while connecting to socket.");
+       return handle_error(zh, lst, "Error while connecting to socket.");
     }
     if ((fds[1]=accept(lst,0,0)) == INVALID_SOCKET){
        closesocket(fds[0]);
-       return handle_error(lst, "Error while accepting socket connection.");
+       return handle_error(zh, lst, "Error while accepting socket connection.");
     }
     closesocket(lst);  
     return 0;
@@ -238,7 +238,7 @@ int adaptor_init(zhandle_t *zh)
 
     /* We use a pipe for interrupting select() in unix/sol and socketpair in windows. */
 #ifdef WIN32   
-    if (create_socket_pair(adaptor_threads->self_pipe) == -1){
+    if (create_socket_pair(zh, adaptor_threads->self_pipe) == -1){
        LOG_ERROR(LOGCALLBACK(zh), "Can't make a socket.");
 #else
     if(pipe(adaptor_threads->self_pipe)==-1) {

Modified: zookeeper/trunk/src/c/src/zk_log.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/zk_log.c?rev=1516123&r1=1516122&r2=1516123&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/zk_log.c (original)
+++ zookeeper/trunk/src/c/src/zk_log.c Wed Aug 21 09:40:42 2013
@@ -127,6 +127,18 @@ void log_message(log_callback_fn callbac
 {
     static const char* dbgLevelStr[]={"ZOO_INVALID","ZOO_ERROR","ZOO_WARN",
             "ZOO_INFO","ZOO_DEBUG"};
+    static pid_t pid=0;
+    va_list va;
+    int ofs = 0;
+#ifdef THREADED
+    unsigned long int tid = 0;
+#endif
+#ifdef WIN32
+    char timebuf [TIME_NOW_BUF_SIZE];
+    const char* time = time_now(timebuf);
+#else
+    const char* time = time_now(get_time_buffer());
+#endif
 
     char* buf = get_format_log_buffer();
     if(!buf)
@@ -135,40 +147,31 @@ void log_message(log_callback_fn callbac
         return;
     }
 
-    static pid_t pid=0;
-
     if(pid==0)
     {
         pid=getpid();
     }
 
-#ifdef WIN32
-    char timebuf [TIME_NOW_BUF_SIZE];
-    const char* time = time_now(timebuf);
-#else
-    const char* time = time_now(get_time_buffer());
-#endif
 
 #ifndef THREADED
 
-    int ofs = snprintf(buf, FORMAT_LOG_BUF_SIZE,
-                       "%s:%d:%s@%s@%d: ", time, pid,
-                       dbgLevelStr[curLevel], funcName, line);
+    ofs = snprintf(buf, FORMAT_LOG_BUF_SIZE,
+                   "%s:%d:%s@%s@%d: ", time, pid,
+                   dbgLevelStr[curLevel], funcName, line);
 #else
 
     #ifdef WIN32
-        unsigned long int tid = (unsigned long int)(pthread_self().thread_id);
+        tid = (unsigned long int)(pthread_self().thread_id);
     #else
-        unsigned long int tid = (unsigned long int)(pthread_self());
+        tid = (unsigned long int)(pthread_self());
     #endif
 
-    int ofs = snprintf(buf, FORMAT_LOG_BUF_SIZE-1,
-                       "%s:%d(0x%lx):%s@%s@%d: ", time, pid, tid,
-                       dbgLevelStr[curLevel], funcName, line);
+    ofs = snprintf(buf, FORMAT_LOG_BUF_SIZE-1,
+                   "%s:%d(0x%lx):%s@%s@%d: ", time, pid, tid,
+                   dbgLevelStr[curLevel], funcName, line);
 #endif
 
     // Now grab the actual message out of the variadic arg list
-    va_list va;
     va_start(va, format);
     vsnprintf(buf+ofs, FORMAT_LOG_BUF_SIZE-1-ofs, format, va);
     va_end(va);



Mime
View raw message