1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Decouple cfg from log

This commit is contained in:
Moritz Grimm 2018-01-19 11:48:57 +01:00
parent d0cf1d8bbd
commit 86bd51b39a
14 changed files with 52 additions and 25 deletions

View File

@ -724,12 +724,14 @@ main(int argc, char *argv[])
ret = 1;
if (0 > cfg_init() ||
0 > cmdline_parse(argc, argv, &ret) ||
0 > log_init() ||
0 > log_init(cfg_get_program_name()) ||
0 > playlist_init() ||
0 > cfg_file_reload() ||
0 > stream_init())
return (ez_shutdown(ret));
log_set_verbosity(cfg_get_program_verbosity());
if (0 > cfg_check(&errstr)) {
log_error("%s: %s", cfg_get_program_config_file(), errstr);
return (ez_shutdown(2));

View File

@ -25,9 +25,10 @@
#include <string.h>
#include <syslog.h>
#include "cfg.h"
#include "log.h"
static unsigned int _log_verbosity;
static int _log(enum log_levels, const char *, ...)
ATTRIBUTE_NONNULL(2)
ATTRIBUTE_FORMAT(printf, 2, 3);
@ -64,18 +65,18 @@ _vlog(enum log_levels lvl, const char *fmt, va_list ap)
p = LOG_WARNING;
break;
case NOTICE:
if (cfg_get_program_verbosity() < 1)
if (_log_verbosity < 1)
return (0);
p = LOG_NOTICE;
break;
case INFO:
if (cfg_get_program_verbosity() < 2)
if (_log_verbosity < 2)
return (0);
p = LOG_INFO;
break;
case DEBUG:
default:
if (cfg_get_program_verbosity() < 3)
if (_log_verbosity < 3)
return (0);
p = LOG_DEBUG;
break;
@ -89,9 +90,9 @@ _vlog(enum log_levels lvl, const char *fmt, va_list ap)
}
int
log_init(void)
log_init(const char *program_name)
{
openlog(cfg_get_program_name(),
openlog(program_name,
LOG_PID|LOG_CONS|LOG_NDELAY|LOG_PERROR,
LOG_USER);
return (0);
@ -103,6 +104,12 @@ log_exit(void)
closelog();
}
void
log_set_verbosity(unsigned int verbosity)
{
_log_verbosity = verbosity;
}
int
log_syserr(enum log_levels lvl, int error, const char *pfx)
{

View File

@ -28,9 +28,11 @@ enum log_levels {
DEBUG
};
int log_init(void);
int log_init(const char *);
void log_exit(void);
void log_set_verbosity(unsigned int);
int log_syserr(enum log_levels, int, const char *);
int log_alert(const char *, ...)

View File

@ -26,6 +26,7 @@ END_TEST
START_TEST(test_program_name)
{
ck_assert_ptr_eq(cfg_get_program_name(), NULL);
TEST_STRLCPY(cfg_set_program_name, cfg_get_program_name, PATH_MAX);
}
END_TEST
@ -197,7 +198,7 @@ void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < log_init())
0 < log_init(NULL))
ck_abort_msg("setup_checked failed");
}

View File

@ -157,7 +157,8 @@ void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < log_init())
0 < cfg_set_program_name("check_cfg_decoder", NULL) ||
0 < log_init(cfg_get_program_name()))
ck_abort_msg("setup_checked failed");
decoders = cfg_decoder_list_create();

View File

@ -149,7 +149,8 @@ void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < log_init())
0 < cfg_set_program_name("check_cfg_encoder", NULL) ||
0 < log_init(cfg_get_program_name()))
ck_abort_msg("setup_checked failed");
encoders = cfg_encoder_list_create();

View File

@ -135,7 +135,8 @@ void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < log_init())
0 < cfg_set_program_name("check_cfg_intake", NULL) ||
0 < log_init(cfg_get_program_name()))
ck_abort_msg("setup_checked failed");
intakes = cfg_intake_list_create();

View File

@ -213,7 +213,8 @@ void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < log_init())
0 < cfg_set_program_name("check_cfg_server", NULL) ||
0 < log_init(cfg_get_program_name()))
ck_abort_msg("setup_checked failed");
servers = cfg_server_list_create();

View File

@ -224,7 +224,8 @@ void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < log_init())
0 < cfg_set_program_name("check_cfg_stream", NULL) ||
0 < log_init(cfg_get_program_name()))
ck_abort_msg("setup_checked failed");
streams = cfg_stream_list_create();

View File

@ -66,7 +66,8 @@ void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < log_init())
0 < cfg_set_program_name("check_cfg_xmlfile", NULL) ||
0 < log_init(cfg_get_program_name()))
ck_abort_msg("setup_checked failed");
}

View File

@ -1,7 +1,6 @@
#include <check.h>
#include <errno.h>
#include "cfg.h"
#include "log.h"
Suite * log_suite(void);
@ -15,7 +14,7 @@ START_TEST(test_log)
ck_assert_int_eq(log_syserr(ALERT, 0, "alert"), 0);
verbosity = 0;
ck_assert_int_eq(cfg_set_program_verbosity(verbosity, NULL), 0);
log_set_verbosity(verbosity);
ck_assert_int_ne(log_alert("alert"), 0);
ck_assert_int_ne(log_syserr(ALERT, EINVAL, "alert"), 0);
ck_assert_int_ne(log_syserr(ALERT, EINVAL, NULL), 0);
@ -26,19 +25,19 @@ START_TEST(test_log)
ck_assert_int_eq(log_notice("notice"), 0);
ck_assert_int_eq(log_syserr(NOTICE, EINVAL, "notice"), 0);
ck_assert_int_eq(cfg_set_program_verbosity(++verbosity, NULL), 0);
log_set_verbosity(++verbosity);
ck_assert_int_ne(log_notice("notice"), 0);
ck_assert_int_ne(log_syserr(NOTICE, EINVAL, "notice"), 0);
ck_assert_int_eq(log_info("info"), 0);
ck_assert_int_eq(log_syserr(INFO, EINVAL, "info"), 0);
ck_assert_int_eq(cfg_set_program_verbosity(++verbosity, NULL), 0);
log_set_verbosity(++verbosity);
ck_assert_int_ne(log_info("info"), 0);
ck_assert_int_ne(log_syserr(INFO, EINVAL, "info"), 0);
ck_assert_int_eq(log_debug("debug"), 0);
ck_assert_int_eq(log_syserr(DEBUG, EINVAL, "debug"), 0);
ck_assert_int_eq(cfg_set_program_verbosity(++verbosity, NULL), 0);
log_set_verbosity(++verbosity);
ck_assert_int_ne(log_debug("debug"), 0);
ck_assert_int_ne(log_syserr(DEBUG, EINVAL, "debug"), 0);
}
@ -63,8 +62,7 @@ log_suite(void)
void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < log_init())
if (0 < log_init("check_log"))
ck_abort_msg("setup_checked failed");
}
@ -72,7 +70,6 @@ void
teardown_checked(void)
{
log_exit();
cfg_exit();
}
int

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include "cfg.h"
#include "log.h"
#include "mdata.h"
@ -180,7 +181,9 @@ mdata_suite(void)
void
setup_checked(void)
{
if (0 < log_init())
if (0 < cfg_init() ||
0 < cfg_set_program_name("check_mdata", NULL) ||
0 < log_init(cfg_get_program_name()))
ck_abort_msg("setup_checked failed");
md = mdata_create();
@ -194,6 +197,7 @@ teardown_checked(void)
ck_assert_ptr_eq(md, NULL);
log_exit();
cfg_exit();
}
int

View File

@ -1,5 +1,7 @@
#include <check.h>
#include "cfg.h"
#include "log.h"
#include "playlist.h"
Suite * playlist_suite(void);
@ -124,7 +126,10 @@ playlist_suite(void)
void
setup_checked(void)
{
if (0 < playlist_init())
if (0 < cfg_init() ||
0 < cfg_set_program_name("check_playlist", NULL) ||
0 < log_init(cfg_get_program_name()) ||
0 < playlist_init())
ck_abort_msg("setup_checked failed");
}

View File

@ -1,6 +1,7 @@
#include <check.h>
#include "cfg.h"
#include "log.h"
#include "mdata.h"
#include "stream.h"
#include "xalloc.h"
@ -120,6 +121,8 @@ void
setup_checked(void)
{
if (0 < cfg_init() ||
0 < cfg_set_program_name("check_stream", NULL) ||
0 < log_init(cfg_get_program_name()) ||
0 < stream_init())
ck_abort_msg("setup_checked failed");
}