aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-05-31 11:32:46 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-05-31 11:32:46 +0200
commit524ce4c40da3b25630dffdd80c5aca99364a3569 (patch)
tree9d6e256f9b818c73d99d56c69da0149b052f2a83
parent06c7e1c7e9aec77a1a22ccb14dd0e540cf08f5d9 (diff)
Add logging by request
Change-Id: I6dda714bcb8c36392c14a1981cfb8960f3db45b8 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--bindings/samples/HelloWorld.c33
-rw-r--r--include/afb/afb-binding-v1.h42
-rw-r--r--include/afb/afb-binding-v2.h25
-rw-r--r--include/afb/afb-binding.h12
-rw-r--r--include/afb/afb-daemon-v1.h43
-rw-r--r--include/afb/afb-daemon-v2.h14
-rw-r--r--include/afb/afb-req-itf.h34
-rw-r--r--src/afb-hook.c24
-rw-r--r--src/afb-hook.h8
-rw-r--r--src/afb-xreq.c22
-rw-r--r--src/verbose.h24
11 files changed, 258 insertions, 23 deletions
diff --git a/bindings/samples/HelloWorld.c b/bindings/samples/HelloWorld.c
index 09c7d3e7..68af5fc6 100644
--- a/bindings/samples/HelloWorld.c
+++ b/bindings/samples/HelloWorld.c
@@ -325,9 +325,39 @@ static void callsync (struct afb_req request)
}
}
+static void verbose (struct afb_req request)
+{
+ int level = 5;
+ json_object *query = afb_req_json(request), *l;
+
+ if (json_object_is_type(query,json_type_int))
+ level = json_object_get_int(query);
+ else if (json_object_object_get_ex(query, "level", &l) && json_object_is_type(l, json_type_int))
+ level = json_object_get_int(l);
+
+ if (!json_object_object_get_ex(query,"message",&l))
+ l = query;
+
+ AFB_REQ_VERBOSE(request, level, "verbose called for %s", json_object_get_string(l));
+ afb_req_success(request, NULL, NULL);
+}
+
static void exitnow (struct afb_req request)
{
- exit(0);
+ int code = 0;
+ json_object *query = afb_req_json(request), *l;
+
+ if (json_object_is_type(query,json_type_int))
+ code = json_object_get_int(query);
+ else if (json_object_object_get_ex(query, "code", &l) && json_object_is_type(l, json_type_int))
+ code = json_object_get_int(l);
+
+ if (!json_object_object_get_ex(query,"reason",&l))
+ l = NULL;
+
+ REQ_NOTICE(request, "in phase of exiting with code %d, reason: %s", code, l ? json_object_get_string(l) : "unknown");
+ afb_req_success(request, NULL, NULL);
+ exit(code);
}
static int preinit()
@@ -365,6 +395,7 @@ static const struct afb_verb_v2 verbs[]= {
{ "eventpush", eventpush , NULL, AFB_SESSION_NONE },
{ "call", call , NULL, AFB_SESSION_NONE },
{ "callsync", callsync , NULL, AFB_SESSION_NONE },
+ { "verbose", verbose , NULL, AFB_SESSION_NONE },
{ "exit", exitnow , NULL, AFB_SESSION_NONE },
{ NULL}
};
diff --git a/include/afb/afb-binding-v1.h b/include/afb/afb-binding-v1.h
index b627d5c4..ef03a6b0 100644
--- a/include/afb/afb-binding-v1.h
+++ b/include/afb/afb-binding-v1.h
@@ -147,20 +147,38 @@ struct afb_binding_interface_v1
*/
#if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
# if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
-# define AFB_ERROR_V1(itf,...) do{if(itf->verbosity>=0)afb_daemon_verbose(itf->daemon,3,__FILE__,__LINE__,__VA_ARGS__);}while(0)
-# define AFB_WARNING_V1(itf,...) do{if(itf->verbosity>=1)afb_daemon_verbose(itf->daemon,4,__FILE__,__LINE__,__VA_ARGS__);}while(0)
-# define AFB_NOTICE_V1(itf,...) do{if(itf->verbosity>=1)afb_daemon_verbose(itf->daemon,5,__FILE__,__LINE__,__VA_ARGS__);}while(0)
-# define AFB_INFO_V1(itf,...) do{if(itf->verbosity>=2)afb_daemon_verbose(itf->daemon,6,__FILE__,__LINE__,__VA_ARGS__);}while(0)
-# define AFB_DEBUG_V1(itf,...) do{if(itf->verbosity>=3)afb_daemon_verbose(itf->daemon,7,__FILE__,__LINE__,__VA_ARGS__);}while(0)
+# define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
+ do{ \
+ if(itf->verbosity>=vlevel) \
+ afb_daemon_verbose2_v1(itf->daemon,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
+ }while(0)
+# define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
+ do{ \
+ if(itf->verbosity>=vlevel) \
+ afb_req_verbose(req,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
+ }while(0)
# else
-# define AFB_ERROR_V1(itf,...) do{if(itf->verbosity>=0)afb_daemon_verbose(itf->daemon,3,NULL,0,__VA_ARGS__);}while(0)
-# define AFB_WARNING_V1(itf,...) do{if(itf->verbosity>=1)afb_daemon_verbose(itf->daemon,4,NULL,0,__VA_ARGS__);}while(0)
-# define AFB_NOTICE_V1(itf,...) do{if(itf->verbosity>=1)afb_daemon_verbose(itf->daemon,5,NULL,0,__VA_ARGS__);}while(0)
-# define AFB_INFO_V1(itf,...) do{if(itf->verbosity>=2)afb_daemon_verbose(itf->daemon,6,NULL,0,__VA_ARGS__);}while(0)
-# define AFB_DEBUG_V1(itf,...) do{if(itf->verbosity>=3)afb_daemon_verbose(itf->daemon,7,NULL,0,__VA_ARGS__);}while(0)
+# define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
+ do{ \
+ if(itf->verbosity>=vlevel) \
+ afb_daemon_verbose_v1(itf->daemon,llevel,NULL,0,NULL,__VA_ARGS__); \
+ }while(0)
+# define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
+ do{ \
+ if(itf->verbosity>=vlevel) \
+ afb_req_verbose(req,llevel,NULL,0,NULL,__VA_ARGS__); \
+ }while(0)
# endif
+# define AFB_ERROR_V1(itf,...) _AFB_LOGGING_V1_(itf,0,3,__VA_ARGS__)
+# define AFB_WARNING_V1(itf,...) _AFB_LOGGING_V1_(itf,1,4,__VA_ARGS__)
+# define AFB_NOTICE_V1(itf,...) _AFB_LOGGING_V1_(itf,1,5,__VA_ARGS__)
+# define AFB_INFO_V1(itf,...) _AFB_LOGGING_V1_(itf,2,6,__VA_ARGS__)
+# define AFB_DEBUG_V1(itf,...) _AFB_LOGGING_V1_(itf,3,7,__VA_ARGS__)
+# define AFB_REQ_ERROR_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,0,3,__VA_ARGS__)
+# define AFB_REQ_WARNING_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,1,4,__VA_ARGS__)
+# define AFB_REQ_NOTICE_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,1,5,__VA_ARGS__)
+# define AFB_REQ_INFO_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,2,6,__VA_ARGS__)
+# define AFB_REQ_DEBUG_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,3,7,__VA_ARGS__)
#endif
-
-
diff --git a/include/afb/afb-binding-v2.h b/include/afb/afb-binding-v2.h
index e763f1cf..66601b23 100644
--- a/include/afb/afb-binding-v2.h
+++ b/include/afb/afb-binding-v2.h
@@ -96,18 +96,33 @@ struct afb_binding_data_v2 AFB_BINDING_DATA_NAME_V2 __attribute__ ((weak));
if(AFB_BINDING_DATA_NAME_V2.verbosity>=vlevel) \
afb_daemon_verbose_v2(llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
}while(0)
+# define _AFB_REQ_LOGGING_V2_(vlevel,llevel,req,...) \
+ do{ \
+ if(AFB_BINDING_DATA_NAME_V2.verbosity>=vlevel) \
+ afb_req_verbose(req,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
+ }while(0)
# else
# define _AFB_LOGGING_V2_(vlevel,llevel,...) \
do{ \
if(afbBindingV2data.verbosity>=vlevel) \
afb_daemon_verbose_v2(llevel,NULL,0,NULL,__VA_ARGS__); \
}while(0)
+# define _AFB_REQ_LOGGING_V2_(vlevel,llevel,req,...) \
+ do{ \
+ if(AFB_BINDING_DATA_NAME_V2.verbosity>=vlevel) \
+ afb_req_verbose(req,llevel,NULL,0,NULL,__VA_ARGS__); \
+ }while(0)
# endif
-# define AFB_ERROR_V2(...) _AFB_LOGGING_V2_(0,3,__VA_ARGS__)
-# define AFB_WARNING_V2(...) _AFB_LOGGING_V2_(1,4,__VA_ARGS__)
-# define AFB_NOTICE_V2(...) _AFB_LOGGING_V2_(1,5,__VA_ARGS__)
-# define AFB_INFO_V2(...) _AFB_LOGGING_V2_(2,6,__VA_ARGS__)
-# define AFB_DEBUG_V2(...) _AFB_LOGGING_V2_(3,7,__VA_ARGS__)
+# define AFB_ERROR_V2(...) _AFB_LOGGING_V2_(0,3,__VA_ARGS__)
+# define AFB_WARNING_V2(...) _AFB_LOGGING_V2_(1,4,__VA_ARGS__)
+# define AFB_NOTICE_V2(...) _AFB_LOGGING_V2_(1,5,__VA_ARGS__)
+# define AFB_INFO_V2(...) _AFB_LOGGING_V2_(2,6,__VA_ARGS__)
+# define AFB_DEBUG_V2(...) _AFB_LOGGING_V2_(3,7,__VA_ARGS__)
+# define AFB_REQ_ERROR_V2(...) _AFB_REQ_LOGGING_V2_(0,3,__VA_ARGS__)
+# define AFB_REQ_WARNING_V2(...) _AFB_REQ_LOGGING_V2_(1,4,__VA_ARGS__)
+# define AFB_REQ_NOTICE_V2(...) _AFB_REQ_LOGGING_V2_(1,5,__VA_ARGS__)
+# define AFB_REQ_INFO_V2(...) _AFB_REQ_LOGGING_V2_(2,6,__VA_ARGS__)
+# define AFB_REQ_DEBUG_V2(...) _AFB_REQ_LOGGING_V2_(3,7,__VA_ARGS__)
#endif
#include "afb-daemon-v2.h"
diff --git a/include/afb/afb-binding.h b/include/afb/afb-binding.h
index e2fd34d8..a7872517 100644
--- a/include/afb/afb-binding.h
+++ b/include/afb/afb-binding.h
@@ -102,6 +102,12 @@
# define INFO AFB_INFO_V1
# define DEBUG AFB_DEBUG_V1
+# define REQ_ERROR AFB_REQ_ERROR_V1
+# define REQ_WARNING AFB_REQ_WARNING_V1
+# define REQ_NOTICE AFB_REQ_NOTICE_V1
+# define REQ_INFO AFB_REQ_INFO_V1
+# define REQ_DEBUG AFB_REQ_DEBUG_V1
+
# endif
#define afb_daemon_get_event_loop afb_daemon_get_event_loop_v1
@@ -147,6 +153,12 @@
# define INFO AFB_INFO_V2
# define DEBUG AFB_DEBUG_V2
+# define REQ_ERROR AFB_REQ_ERROR_V2
+# define REQ_WARNING AFB_REQ_WARNING_V2
+# define REQ_NOTICE AFB_REQ_NOTICE_V2
+# define REQ_INFO AFB_REQ_INFO_V2
+# define REQ_DEBUG AFB_REQ_DEBUG_V2
+
# endif
#define afb_daemon_get_event_loop afb_daemon_get_event_loop_v2
diff --git a/include/afb/afb-daemon-v1.h b/include/afb/afb-daemon-v1.h
index 84095e04..6390dd16 100644
--- a/include/afb/afb-daemon-v1.h
+++ b/include/afb/afb-daemon-v1.h
@@ -74,8 +74,21 @@ static inline struct afb_event afb_daemon_make_event_v1(struct afb_daemon daemon
/*
* Send a message described by 'fmt' and following parameters
* to the journal for the verbosity 'level'.
- * 'file' and 'line' are indicators of position of the code in source files.
+ *
+ * 'file' and 'line' are indicators of position of the code in source files
+ * (see macros __FILE__ and __LINE__).
+ *
* 'daemon' MUST be the daemon given in interface when activating the binding.
+ *
+ * 'level' is defined by syslog standard:
+ * EMERGENCY 0 System is unusable
+ * ALERT 1 Action must be taken immediately
+ * CRITICAL 2 Critical conditions
+ * ERROR 3 Error conditions
+ * WARNING 4 Warning conditions
+ * NOTICE 5 Normal but significant condition
+ * INFO 6 Informational
+ * DEBUG 7 Debug-level messages
*/
static inline void afb_daemon_verbose_v1(struct afb_daemon daemon, int level, const char *file, int line, const char *fmt, ...) __attribute__((format(printf, 5, 6)));
static inline void afb_daemon_verbose_v1(struct afb_daemon daemon, int level, const char *file, int line, const char *fmt, ...)
@@ -87,6 +100,34 @@ static inline void afb_daemon_verbose_v1(struct afb_daemon daemon, int level, co
}
/*
+ * Send a message described by 'fmt' and following parameters
+ * to the journal for the verbosity 'level'.
+ *
+ * 'file', 'line' and 'func' are indicators of position of the code in source files
+ * (see macros __FILE__, __LINE__ and __func__).
+ *
+ * 'daemon' MUST be the daemon given in interface when activating the binding.
+ *
+ * 'level' is defined by syslog standard:
+ * EMERGENCY 0 System is unusable
+ * ALERT 1 Action must be taken immediately
+ * CRITICAL 2 Critical conditions
+ * ERROR 3 Error conditions
+ * WARNING 4 Warning conditions
+ * NOTICE 5 Normal but significant condition
+ * INFO 6 Informational
+ * DEBUG 7 Debug-level messages
+ */
+static inline void afb_daemon_verbose2_v1(struct afb_daemon daemon, int level, const char *file, int line, const char *func, const char *fmt, ...) __attribute__((format(printf, 6, 7)));
+static inline void afb_daemon_verbose2_v1(struct afb_daemon daemon, int level, const char *file, int line, const char *func, const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ daemon.itf->vverbose_v2(daemon.closure, level, file, line, func, fmt, args);
+ va_end(args);
+}
+
+/*
* Get the root directory file descriptor. This file descriptor can
* be used with functions 'openat', 'fstatat', ...
*/
diff --git a/include/afb/afb-daemon-v2.h b/include/afb/afb-daemon-v2.h
index 3ecd763b..6cfc60ba 100644
--- a/include/afb/afb-daemon-v2.h
+++ b/include/afb/afb-daemon-v2.h
@@ -69,7 +69,19 @@ static inline struct afb_event afb_daemon_make_event_v2(const char *name)
/*
* Send a message described by 'fmt' and following parameters
* to the journal for the verbosity 'level'.
- * 'file' and 'line' are indicators of position of the code in source files.
+ *
+ * 'file', 'line' and 'func' are indicators of position of the code in source files
+ * (see macros __FILE__, __LINE__ and __func__).
+ *
+ * 'level' is defined by syslog standard:
+ * EMERGENCY 0 System is unusable
+ * ALERT 1 Action must be taken immediately
+ * CRITICAL 2 Critical conditions
+ * ERROR 3 Error conditions
+ * WARNING 4 Warning conditions
+ * NOTICE 5 Normal but significant condition
+ * INFO 6 Informational
+ * DEBUG 7 Debug-level messages
*/
static inline void afb_daemon_verbose_v2(int level, const char *file, int line, const char * func, const char *fmt, ...) __attribute__((format(printf, 5, 6)));
static inline void afb_daemon_verbose_v2(int level, const char *file, int line, const char * func, const char *fmt, ...)
diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h
index 65f2bfe6..8c18a831 100644
--- a/include/afb/afb-req-itf.h
+++ b/include/afb/afb-req-itf.h
@@ -67,6 +67,8 @@ struct afb_req_itf {
void (*subcall)(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure);
int (*subcallsync)(void *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result);
+
+ void (*vverbose)(void*closure, int level, const char *file, int line, const char * func, const char *fmt, va_list args);
};
/*
@@ -390,3 +392,35 @@ static inline int afb_req_subcall_sync(struct afb_req req, const char *api, cons
return req.itf->subcallsync(req.closure, api, verb, args, result);
}
+/*
+ * Send associated to 'req' a message described by 'fmt' and following parameters
+ * to the journal for the verbosity 'level'.
+ *
+ * 'file', 'line' and 'func' are indicators of position of the code in source files
+ * (see macros __FILE__, __LINE__ and __func__).
+ *
+ * 'level' is defined by syslog standard:
+ * EMERGENCY 0 System is unusable
+ * ALERT 1 Action must be taken immediately
+ * CRITICAL 2 Critical conditions
+ * ERROR 3 Error conditions
+ * WARNING 4 Warning conditions
+ * NOTICE 5 Normal but significant condition
+ * INFO 6 Informational
+ * DEBUG 7 Debug-level messages
+ */
+static inline void afb_req_verbose(struct afb_req req, int level, const char *file, int line, const char * func, const char *fmt, ...) __attribute__((format(printf, 6, 7)));
+static inline void afb_req_verbose(struct afb_req req, int level, const char *file, int line, const char * func, const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ req.itf->vverbose(req.closure, level, file, line, func, fmt, args);
+ va_end(args);
+}
+
+/* macro for setting file, line and function automatically */
+# if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
+#define AFB_REQ_VERBOSE(req,level,...) afb_req_verbose(req,level,__FILE__,__LINE__,__func__,__VA_ARGS__)
+#else
+#define AFB_REQ_VERBOSE(req,level,...) afb_req_verbose(req,level,NULL,0,NULL,__VA_ARGS__)
+#endif
diff --git a/src/afb-hook.c b/src/afb-hook.c
index cade990c..6afcd2fb 100644
--- a/src/afb-hook.c
+++ b/src/afb-hook.c
@@ -210,6 +210,24 @@ static void hook_xreq_subcallsync_result_default_cb(void * closure, const struct
_hook_xreq_(xreq, " ...subcallsync... -> %d: %s", status, json_object_to_json_string(result));
}
+static void hook_xreq_vverbose_default_cb(void * closure, const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
+{
+ int len;
+ char *msg;
+ va_list ap;
+
+ va_copy(ap, args);
+ len = vasprintf(&msg, fmt, ap);
+ va_end(ap);
+
+ if (len < 0)
+ _hook_xreq_(xreq, "vverbose(%d, %s, %d, %s) -> %s ? ? ?", level, file, line, func, fmt);
+ else {
+ _hook_xreq_(xreq, "vverbose(%d, %s, %d, %s) -> %s", level, file, line, func, msg);
+ free(msg);
+ }
+}
+
static struct afb_hook_xreq_itf hook_xreq_default_itf = {
.hook_xreq_begin = hook_xreq_begin_default_cb,
.hook_xreq_end = hook_xreq_end_default_cb,
@@ -229,6 +247,7 @@ static struct afb_hook_xreq_itf hook_xreq_default_itf = {
.hook_xreq_subcall_result = hook_xreq_subcall_result_default_cb,
.hook_xreq_subcallsync = hook_xreq_subcallsync_default_cb,
.hook_xreq_subcallsync_result = hook_xreq_subcallsync_result_default_cb,
+ .hook_xreq_vverbose = hook_xreq_vverbose_default_cb
};
/******************************************************************************
@@ -349,6 +368,11 @@ int afb_hook_xreq_subcallsync_result(const struct afb_xreq *xreq, int status, st
return status;
}
+void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
+{
+ _HOOK_XREQ_(vverbose, xreq, level, file ?: "?", line, func ?: "?", fmt, args);
+}
+
/******************************************************************************
* section: hooking xreqs
*****************************************************************************/
diff --git a/src/afb-hook.h b/src/afb-hook.h
index 8fe30d5b..c1ff8476 100644
--- a/src/afb-hook.h
+++ b/src/afb-hook.h
@@ -17,6 +17,8 @@
#pragma once
+#include <stdarg.h>
+
struct req;
struct afb_context;
struct json_object;
@@ -53,6 +55,7 @@ struct afb_hook_xreq;
#define afb_hook_flag_req_subcall_result 0x010800
#define afb_hook_flag_req_subcallsync 0x020000
#define afb_hook_flag_req_subcallsync_result 0x040000
+#define afb_hook_flag_req_vverbose 0x080000
/* common flags */
#define afb_hook_flags_req_life (afb_hook_flag_req_begin|afb_hook_flag_req_end)
@@ -69,7 +72,8 @@ struct afb_hook_xreq;
/* predefined groups */
#define afb_hook_flags_req_common (afb_hook_flags_req_life|afb_hook_flags_req_args|afb_hook_flags_req_result\
- |afb_hook_flags_req_session|afb_hook_flags_req_event|afb_hook_flags_req_subcall)
+ |afb_hook_flags_req_session|afb_hook_flags_req_event|afb_hook_flags_req_subcall\
+ |afb_hook_flag_req_vverbose)
#define afb_hook_flags_req_extra (afb_hook_flags_req_common|afb_hook_flags_req_ref|afb_hook_flags_req_context)
#define afb_hook_flags_req_all (afb_hook_flags_req_extra)
@@ -92,6 +96,7 @@ struct afb_hook_xreq_itf {
void (*hook_xreq_subcall_result)(void * closure, const struct afb_xreq *xreq, int status, struct json_object *result);
void (*hook_xreq_subcallsync)(void * closure, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
void (*hook_xreq_subcallsync_result)(void * closure, const struct afb_xreq *xreq, int status, struct json_object *result);
+ void (*hook_xreq_vverbose)(void * closure, const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args);
};
extern void afb_hook_init_xreq(struct afb_xreq *xreq);
@@ -119,6 +124,7 @@ extern void afb_hook_xreq_subcall(const struct afb_xreq *xreq, const char *api,
extern void afb_hook_xreq_subcall_result(const struct afb_xreq *xreq, int status, struct json_object *result);
extern void afb_hook_xreq_subcallsync(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
extern int afb_hook_xreq_subcallsync_result(const struct afb_xreq *xreq, int status, struct json_object *result);
+extern void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args);
/*********************************************************
* section hooking ditf (daemon interface)
diff --git a/src/afb-xreq.c b/src/afb-xreq.c
index 0b828277..61ba4fd9 100644
--- a/src/afb-xreq.c
+++ b/src/afb-xreq.c
@@ -257,6 +257,12 @@ static int xreq_subcallsync_cb(void *closure, const char *api, const char *verb,
return 1;
}
+static void xreq_vverbose_cb(void*closure, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
+{
+ /* TODO: improves the implementation. example: on condition make a list of log messages that will be returned */
+ vverbose(level, file, line, func, fmt, args);
+}
+
/******************************************************************************/
static struct json_object *xreq_hooked_json_cb(void *closure)
@@ -397,6 +403,16 @@ static int xreq_hooked_subcallsync_cb(void *closure, const char *api, const char
return afb_hook_xreq_subcallsync_result(xreq, r, *result);
}
+static void xreq_hooked_vverbose_cb(void*closure, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
+{
+ struct afb_xreq *xreq = closure;
+ va_list ap;
+ va_copy(ap, args);
+ xreq_vverbose_cb(closure, level, file, line, func, fmt, args);
+ afb_hook_xreq_vverbose(xreq, level, file, line, func, fmt, ap);
+ va_end(ap);
+}
+
/******************************************************************************/
const struct afb_req_itf xreq_itf = {
@@ -415,7 +431,8 @@ const struct afb_req_itf xreq_itf = {
.subscribe = xreq_subscribe_cb,
.unsubscribe = xreq_unsubscribe_cb,
.subcall = xreq_subcall_cb,
- .subcallsync = xreq_subcallsync_cb
+ .subcallsync = xreq_subcallsync_cb,
+ .vverbose = xreq_vverbose_cb
};
const struct afb_req_itf xreq_hooked_itf = {
@@ -434,7 +451,8 @@ const struct afb_req_itf xreq_hooked_itf = {
.subscribe = xreq_hooked_subscribe_cb,
.unsubscribe = xreq_hooked_unsubscribe_cb,
.subcall = xreq_hooked_subcall_cb,
- .subcallsync = xreq_hooked_subcallsync_cb
+ .subcallsync = xreq_hooked_subcallsync_cb,
+ .vverbose = xreq_hooked_vverbose_cb
};
static inline struct afb_req to_req(struct afb_xreq *xreq)
diff --git a/src/verbose.h b/src/verbose.h
index 71d5fe1e..6bedc323 100644
--- a/src/verbose.h
+++ b/src/verbose.h
@@ -20,9 +20,33 @@
#include <stdarg.h>
+/*
+ verbosity tune the count of reported messages
+
+ verbosity value : reported messages
+ ----------------+------------------------
+ lesser than 0 : no message at all
+ 0 : ERROR
+ 1 : ERROR, WARNING, NOTICE
+ 2 : ERROR, WARNING, NOTICE, INFO
+ greater than 2 : ERROR, WARNING, NOTICE, INFO, DEBUG
+
+*/
extern int verbosity;
extern void verbose_set_name(const char *name, int authority);
+
+/*
+ Level is defined by syslog standard:
+ KERN_EMERG 0 System is unusable
+ KERN_ALERT 1 Action must be taken immediately
+ KERN_CRIT 2 Critical conditions
+ KERN_ERR 3 Error conditions
+ KERN_WARNING 4 Warning conditions
+ KERN_NOTICE 5 Normal but significant condition
+ KERN_INFO 6 Informational
+ KERN_DEBUG 7 Debug-level messages
+*/
extern void verbose(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__((format(printf, 5, 6)));
extern void vverbose(int level, const char *file, int line, const char *function, const char *fmt, va_list args);