added syslog logger

pull/1/head
Falk Werner 4 years ago
parent 5a58025e4a
commit 609fbee24f

@ -60,6 +60,7 @@ add_library(webfused-static STATIC
src/webfused/auth/file_authenticator.c
src/webfused/log/logger.c
src/webfused/log/stderr_logger.c
src/webfused/log/syslog_logger.c
)
add_executable(webfused

@ -13,8 +13,9 @@
#include <webfuse_adapter.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/log/stderr_logger.h"
#include "webfused/log/log.h"
#include "webfused/log/logger.h"
#include "webfused/log/stderr_logger.h"
#define WFD_SERVICE_TIMEOUT (1 * 1000)
#define WFD_DEFAULT_CONFIG_FILE ("/etc/webfuse.conf")
@ -141,6 +142,7 @@ int wfd_daemon_run(int argc, char * argv[])
show_help();
}
wfd_logger_close();
free(args.config_file);
return result;
}

@ -0,0 +1,56 @@
#include "webfused/log/syslog_logger.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include <syslog.h>
#include <stddef.h>
static int
wfd_syslog_logger_to_priority(
int level)
{
switch (level)
{
case WFD_LOGLEVEL_FATAL: return LOG_CRIT;
case WFD_LOGLEVEL_ERROR: return LOG_ERR;
case WFD_LOGLEVEL_WARN: return LOG_WARNING;
case WFD_LOGLEVEL_INFO: return LOG_INFO;
case WFD_LOGLEVEL_DEBUG: return LOG_DEBUG;
default: return LOG_NOTICE;
}
}
static void
wfd_syslog_logger_log(
void * user_data,
int level,
char const * format,
va_list args)
{
(void) user_data;
int prio = wfd_syslog_logger_to_priority(level);
vsyslog(prio, format, args);
}
static void
wfd_syslog_logger_close(
void * user_data)
{
closelog();
}
void
wfd_syslog_logger_init(
int level,
char const * ident,
int options,
int facility)
{
wfd_logger_init(level,
&wfd_syslog_logger_log,
&wfd_syslog_logger_close,
NULL);
openlog(ident, options, facility);
}

@ -0,0 +1,20 @@
#ifndef WFD_LOG_SYSLOG_LOGGER_H
#define WFD_LOG_SYSLOG_LOGGER_H
#ifdef __cplusplus
extern "C"
{
#endif
extern void
wfd_syslog_logger_init(
int level,
char const * ident,
int options,
int facility);
#ifdef __cplusplus
}
#endif
#endif
Loading…
Cancel
Save