From 1d6cf993b7655244d5cdb668a2ea2fc6bb5214cf Mon Sep 17 00:00:00 2001 From: Emanuele Di Pascale Date: Fri, 25 Jan 2019 14:40:27 +0100 Subject: [PATCH] lib: add hooks for external logging function Signed-off-by: Emanuele Di Pascale --- lib/log.c | 8 ++++++++ lib/log.h | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/lib/log.c b/lib/log.c index 12a1d7fbe0..f936957611 100644 --- a/lib/log.c +++ b/lib/log.c @@ -29,6 +29,7 @@ #include "memory.h" #include "command.h" #include "lib_errors.h" +#include "lib/hook.h" #ifndef SUNOS_5 #include @@ -46,6 +47,10 @@ DEFINE_MTYPE_STATIC(LIB, ZLOG, "Logging") +/* hook for external logging */ +DEFINE_HOOK(zebra_ext_log, (int priority, const char *format, va_list args), + (priority, format, args)); + static int logfile_fd = -1; /* Used in signal handler. */ struct zlog *zlog_default = NULL; @@ -213,6 +218,9 @@ void vzlog(int priority, const char *format, va_list args) tsctl.already_rendered = 0; struct zlog *zl = zlog_default; + /* call external hook */ + hook_call(zebra_ext_log, priority, format, args); + /* When zlog_default is also NULL, use stderr for logging. */ if (zl == NULL) { tsctl.precision = 0; diff --git a/lib/log.h b/lib/log.h index be1d9fb592..8fb98a02ab 100644 --- a/lib/log.h +++ b/lib/log.h @@ -26,6 +26,12 @@ #include #include #include +#include +#include "lib/hook.h" + +/* Hook for external logging function */ +DECLARE_HOOK(zebra_ext_log, (int priority, const char *format, va_list args), + (priority, format, args)); /* Here is some guidance on logging levels to use: * -- 2.39.5