aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/netconf-pnp-simulator/engine/patches/sysrepo/02-zlog.patch
blob: 0223563c3af1dd151c721be6157599b1f6ba95da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 14c8467..5af087e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -105,6 +105,11 @@ configure_file(${PROJECT_SOURCE_DIR}/inc/sysrepo/values.h.in ${PROJECT_BINARY_DI
 configure_file(${PROJECT_SOURCE_DIR}/inc/sysrepo/xpath.h ${PROJECT_BINARY_DIR}/inc/sysrepo/xpath.h COPYONLY)

 # find required libraries
+find_library(ZLOG zlog)
+if(NOT ZLOG)
+    message(FATAL_ERROR "zlog must be installed.")
+endif()
+
 find_package(EV REQUIRED)
 include_directories(${EV_INCLUDE_DIR})

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 342ad9d..d026a81 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -85,9 +85,9 @@ add_dependencies(SR_SRC COMMON)
 add_dependencies(SR_ENGINE COMMON)

 if(USE_AVL_LIB)
-    set(LINK_LIBRARIES pthread ${AVL_LIBRARIES} ${EV_LIBRARIES} ${PROTOBUF-C_LIBRARIES} ${YANG_LIBRARIES})
+    set(LINK_LIBRARIES pthread ${AVL_LIBRARIES} ${EV_LIBRARIES} ${PROTOBUF-C_LIBRARIES} ${YANG_LIBRARIES} ${ZLOG})
 else(USE_AVL_LIB)
-    set(LINK_LIBRARIES pthread ${REDBLACK_LIBRARIES} ${EV_LIBRARIES} ${PROTOBUF-C_LIBRARIES} ${YANG_LIBRARIES})
+    set(LINK_LIBRARIES pthread ${REDBLACK_LIBRARIES} ${EV_LIBRARIES} ${PROTOBUF-C_LIBRARIES} ${YANG_LIBRARIES} ${ZLOG})
 endif(USE_AVL_LIB)

 #handle rt library that doesn't exist on OS X
diff --git a/src/common/sr_logger.c b/src/common/sr_logger.c
index 8dd6f31..ea94044 100644
--- a/src/common/sr_logger.c
+++ b/src/common/sr_logger.c
@@ -29,6 +29,8 @@
 #include <stdarg.h>
 #include <pthread.h>

+#include <zlog.h>
+
 #include "sr_common.h"
 #include "sr_logger.h"

@@ -76,6 +78,7 @@ void
 sr_logger_init(const char *app_name)
 {
 #if SR_LOGGING_ENABLED
+    dzlog_init("/opt/etc/zlog.conf", app_name);
     if (NULL != sr_syslog_identifier) {
         /* if some syslog identifier was already set, release it as we are going to set new one */
         free((char*)sr_syslog_identifier);
diff --git a/src/common/sr_logger.h b/src/common/sr_logger.h
index 37c3487..c95a68d 100644
--- a/src/common/sr_logger.h
+++ b/src/common/sr_logger.h
@@ -31,6 +31,8 @@
 #include <syslog.h>
 #include <pthread.h>

+#include <zlog.h>
+
 #include "sr_constants.h"

 /**
@@ -156,37 +158,31 @@ extern __thread char strerror_buf [SR_MAX_STRERROR_LEN]; /**< thread local buffe
 /**
  * Internal output macro
  */
-#define SR_LOG__INTERNAL(LL, MSG, ...) \
-    do { \
-        if (sr_ll_stderr >= LL) \
-            SR_LOG__STDERR(LL, MSG, __VA_ARGS__) \
-        if (sr_ll_syslog >= LL) \
-            SR_LOG__SYSLOG(LL, MSG, __VA_ARGS__) \
-        if (NULL != sr_log_callback) \
-            SR_LOG__CALLBACK(LL, MSG, __VA_ARGS__) \
-    } while(0)
-
 #if SR_LOGGING_ENABLED

 /** Prints an error message (with format specifiers). */
-#define SR_LOG_ERR(MSG, ...) SR_LOG__INTERNAL(SR_LL_ERR, MSG, __VA_ARGS__)
+#define SR_LOG_ERR(MSG, ...) dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, \
+        __LINE__, ZLOG_LEVEL_ERROR, MSG, __VA_ARGS__)
 /** Prints an error message. */
-#define SR_LOG_ERR_MSG(MSG) SR_LOG__INTERNAL(SR_LL_ERR, MSG "%s", "")
+#define SR_LOG_ERR_MSG(MSG) SR_LOG_ERR(MSG "%s", "")

 /** Prints a warning message (with format specifiers). */
-#define SR_LOG_WRN(MSG, ...) SR_LOG__INTERNAL(SR_LL_WRN, MSG, __VA_ARGS__)
+#define SR_LOG_WRN(MSG, ...) dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, \
+        __LINE__, ZLOG_LEVEL_WARN, MSG, __VA_ARGS__)
 /** Prints a warning message. */
-#define SR_LOG_WRN_MSG(MSG) SR_LOG__INTERNAL(SR_LL_WRN, MSG "%s", "")
+#define SR_LOG_WRN_MSG(MSG) SR_LOG_WRN(MSG "%s", "")

 /** Prints an informational message (with format specifiers). */
-#define SR_LOG_INF(MSG, ...) SR_LOG__INTERNAL(SR_LL_INF, MSG, __VA_ARGS__)
+#define SR_LOG_INF(MSG, ...) dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, \
+        __LINE__, ZLOG_LEVEL_INFO, MSG, __VA_ARGS__)
 /** Prints an informational message. */
-#define SR_LOG_INF_MSG(MSG) SR_LOG__INTERNAL(SR_LL_INF, MSG "%s", "")
+#define SR_LOG_INF_MSG(MSG) SR_LOG_INF(MSG "%s", "")

 /** Prints a development debug message (with format specifiers). */
-#define SR_LOG_DBG(MSG, ...) SR_LOG__INTERNAL(SR_LL_DBG, MSG, __VA_ARGS__)
+#define SR_LOG_DBG(MSG, ...) dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, \
+        __LINE__, ZLOG_LEVEL_DEBUG, MSG, __VA_ARGS__)
 /** Prints a development debug message. */
-#define SR_LOG_DBG_MSG(MSG) SR_LOG__INTERNAL(SR_LL_DBG, MSG "%s", "")
+#define SR_LOG_DBG_MSG(MSG) SR_LOG_DBG(MSG "%s", "")

 #else
 #define SR_LOG_ERR(...)
diff --git a/src/executables/sysrepocfg.c b/src/executables/sysrepocfg.c
index 0000951..f48ed5e 100644
--- a/src/executables/sysrepocfg.c
+++ b/src/executables/sysrepocfg.c
@@ -2000,6 +2000,9 @@ main(int argc, char* argv[])
         }
     }

+    /* init logger */
+    sr_logger_init("sysrepocfg");
+
     /* set log levels */
     sr_log_stderr(SR_LL_ERR);
     sr_log_syslog(SR_LL_NONE);
diff --git a/src/executables/sysrepoctl.c b/src/executables/sysrepoctl.c
index 3b02e7d..60ffd7e 100644
--- a/src/executables/sysrepoctl.c
+++ b/src/executables/sysrepoctl.c
@@ -1311,6 +1311,9 @@ main(int argc, char* argv[])
         search_dir_count = 1;
     }

+    /* init logger */
+    sr_logger_init("sysrepoctl");
+
     /* set log levels */
     sr_log_stderr(SR_LL_ERR);
     sr_log_syslog(SR_LL_NONE);
diff --git a/src/clientlib/client_library.c b/src/clientlib/client_library.c
index c3da2e5..b3beab7 100644
--- a/src/clientlib/client_library.c
+++ b/src/clientlib/client_library.c
@@ -377,6 +377,11 @@ sr_connect(const char *app_name, const sr_conn_options_t opts, sr_conn_ctx_t **c

     CHECK_NULL_ARG2(app_name, conn_ctx_p);

+    if (0 == connections_cnt) {
+        /* this is the first connection - initialize logging */
+        sr_logger_init(app_name);
+    }
+
     SR_LOG_DBG_MSG("Connecting to Sysrepo Engine.");

     /* create the connection */
@@ -385,11 +390,6 @@ sr_connect(const char *app_name, const sr_conn_options_t opts, sr_conn_ctx_t **c

     pthread_mutex_lock(&global_lock);

-    if (0 == connections_cnt) {
-        /* this is the first connection - initialize logging */
-        sr_logger_init(app_name);
-    }
-
     /* attempt to connect to sysrepo daemon socket */
     rc = cl_socket_connect(connection, SR_DAEMON_SOCKET);
     if (SR_ERR_OK != rc) {