From de270c535d4f2d027b8cd00ac3cbca86f21f7d38 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Fri, 2 Oct 2020 11:02:07 +0000 Subject: [PATCH] Feature: Allow setting memory backlog for logfiles --- src/cfgfile.c | 29 +++++++++++++++++++++++++++++ src/cfgfile.h | 3 +++ src/logging.c | 4 ++++ src/main.c | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/src/cfgfile.c b/src/cfgfile.c index 499184ad..3081ab47 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -68,6 +68,7 @@ #define CONFIG_DEFAULT_ACCESS_LOG "access.log" #define CONFIG_DEFAULT_ERROR_LOG "error.log" #define CONFIG_DEFAULT_LOG_LEVEL ICECAST_LOGLEVEL_INFO +#define CONFIG_DEFAULT_LOG_LINES_KEPT 64 #define CONFIG_DEFAULT_CHROOT 0 #define CONFIG_DEFAULT_CHUID 0 #define CONFIG_DEFAULT_USER NULL @@ -912,6 +913,12 @@ static void _set_defaults(ice_config_t *configuration) ->error_log = (char *) xmlCharStrdup(CONFIG_DEFAULT_ERROR_LOG); configuration ->loglevel = CONFIG_DEFAULT_LOG_LEVEL; + configuration + ->playlist_log_lines_kept = CONFIG_DEFAULT_LOG_LINES_KEPT; + configuration + ->access_log_lines_kept = CONFIG_DEFAULT_LOG_LINES_KEPT; + configuration + ->error_log_lines_kept = CONFIG_DEFAULT_LOG_LINES_KEPT; configuration ->chroot = CONFIG_DEFAULT_CHROOT; configuration @@ -2394,6 +2401,28 @@ static void _parse_logging(xmlDocPtr doc, } else { ICECAST_LOG_WARN(" must not be empty."); } + } else if (xmlStrcmp(node->name, XMLSTR("memorybacklog")) == 0) { + int val = CONFIG_DEFAULT_LOG_LINES_KEPT; + char *logfile = (char *)xmlGetProp(node, XMLSTR("logfile")); + + __read_int(doc, node, &val, " must not be empty."); + + if (logfile) { + if (!strcmp(logfile, "error")) { + configuration->error_log_lines_kept = val; + } else if (!strcmp(logfile, "access")) { + configuration->access_log_lines_kept = val; + } else if (!strcmp(logfile, "playlist")) { + configuration->playlist_log_lines_kept = val; + } else { + ICECAST_LOG_WARN("Invalid logfile for : %H", logfile); + } + xmlFree(logfile); + } else { + configuration->error_log_lines_kept = val; + configuration->access_log_lines_kept = val; + configuration->playlist_log_lines_kept = val; + } } } while ((node = node->next)); } diff --git a/src/cfgfile.h b/src/cfgfile.h index 5ec6e5ab..a168d90e 100644 --- a/src/cfgfile.h +++ b/src/cfgfile.h @@ -261,6 +261,9 @@ struct ice_config_tag { int loglevel; int logsize; int logarchive; + size_t access_log_lines_kept; + size_t error_log_lines_kept; + size_t playlist_log_lines_kept; config_tls_context_t tls_context; diff --git a/src/logging.c b/src/logging.c index 145dbfcc..a4d4be96 100644 --- a/src/logging.c +++ b/src/logging.c @@ -249,4 +249,8 @@ void restart_logging (ice_config_t *config) log_set_archive_timestamp (playlistlog, config->logarchive); log_reopen (playlistlog); } + + log_set_lines_kept(errorlog, config->error_log_lines_kept); + log_set_lines_kept(accesslog, config->access_log_lines_kept); + log_set_lines_kept(playlistlog, config->playlist_log_lines_kept); } diff --git a/src/main.c b/src/main.c index 91ae7284..bf7eecfc 100644 --- a/src/main.c +++ b/src/main.c @@ -343,6 +343,10 @@ static int _start_logging(void) log_set_level(accesslog, 4); log_set_level(playlistlog, 4); + log_set_lines_kept(errorlog, config->error_log_lines_kept); + log_set_lines_kept(accesslog, config->access_log_lines_kept); + log_set_lines_kept(playlistlog, config->playlist_log_lines_kept); + if (errorlog >= 0 && accesslog >= 0) return 1; return 0;