Skip to content
Snippets Groups Projects
Commit 0483ace2 authored by Nikita Pettik's avatar Nikita Pettik Committed by Aleksandr Lyapunov
Browse files

say: introduce on_log callback

It can be used for instance to duplicate logs somewhere. In particular
case it is going to be used for flight recorder.

NO_DOC=<No user visible changes>
NO_TEST=<No functional changes>
NO_CHANGELOG=<No functional changes>
parent de90e54b
No related branches found
No related tags found
No related merge requests found
......@@ -87,6 +87,7 @@ static struct log log_boot = {
.format_func = say_format_boot,
.pid = 0,
.syslog_ident = NULL,
.on_log = NULL,
};
/** Default logger used after bootstrap. */
......@@ -224,6 +225,12 @@ say_set_log_format(enum say_format format)
log_format = format;
}
void
say_set_log_callback(log_callback_t callback)
{
log_default->on_log = callback;
}
static const char *say_format_strs[] = {
[SF_PLAIN] = "plain",
[SF_JSON] = "json",
......@@ -634,6 +641,7 @@ log_create(struct log *log, const char *init_str, int nonblock)
log->format_func = NULL;
log->level = S_INFO;
log->rotating_threads = 0;
log->on_log = NULL;
fiber_cond_create(&log->rotate_cond);
ev_async_init(&log->log_async, log_rotate_async_cb);
setvbuf(stderr, NULL, _IONBF, 0);
......@@ -1232,6 +1240,12 @@ log_vsay(struct log *log, int level, const char *filename, int line,
const char *error, const char *format, va_list ap)
{
int errsv = errno;
if (log->on_log != NULL) {
va_list ap_copy;
va_copy(ap_copy, ap);
log->on_log(level, filename, line, error, format, ap_copy);
va_end(ap_copy);
}
if (level > log->level) {
return 0;
}
......
......@@ -140,6 +140,10 @@ typedef int (*log_format_func_t)(struct log *log, char *buf, int len, int level,
const char *filename, int line, const char *error,
const char *format, va_list ap);
typedef void
(*log_callback_t)(int level, const char *filename, int line,
const char *error, const char *format, va_list ap);
/**
* A log object. There is a singleton for the default log.
*/
......@@ -175,6 +179,8 @@ struct log {
int rotating_threads;
enum syslog_facility syslog_facility;
struct rlist in_log_list;
/** Callback called on log event. */
log_callback_t on_log;
};
/**
......@@ -263,6 +269,12 @@ say_set_log_level(int new_level);
void
say_set_log_format(enum say_format format);
/**
* Set callback function called on each log event.
*/
void
say_set_log_callback(log_callback_t callback);
/**
* Return say format by name.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment