mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 00:04:53 +00:00
Add option to logger to rename log files with timestamp (issue #8020 reported by jmls)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@44172 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
2
CHANGES
2
CHANGES
@@ -19,3 +19,5 @@ Changes since Asterisk 1.4-beta was branched:
|
|||||||
and/or H.450 supplementary service)
|
and/or H.450 supplementary service)
|
||||||
* Added keepstats option to queues.conf which will keep queue
|
* Added keepstats option to queues.conf which will keep queue
|
||||||
statistics during a reload.
|
statistics during a reload.
|
||||||
|
* Added rotatetimestamp option to logger.conf which will use
|
||||||
|
the time to name the logger files instead of sequence number.
|
||||||
|
@@ -24,6 +24,11 @@
|
|||||||
; (defaults to queue_log)
|
; (defaults to queue_log)
|
||||||
;queue_log_name = queue_log
|
;queue_log_name = queue_log
|
||||||
;
|
;
|
||||||
|
; Rename the logfiles using a timestamp instead of a
|
||||||
|
; sequence number when "logger rotate" is executed
|
||||||
|
; (defaults to no).
|
||||||
|
;rotatetimestamp = yes
|
||||||
|
;
|
||||||
; This determines whether or not we log generic events to a file
|
; This determines whether or not we log generic events to a file
|
||||||
; (defaults to yes).
|
; (defaults to yes).
|
||||||
;event_log = no
|
;event_log = no
|
||||||
|
@@ -87,6 +87,7 @@ static char queue_log_name[256] = QUEUELOG;
|
|||||||
|
|
||||||
static int filesize_reload_needed = 0;
|
static int filesize_reload_needed = 0;
|
||||||
static int global_logmask = -1;
|
static int global_logmask = -1;
|
||||||
|
static int rotatetimestamp = 0;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
unsigned int queue_log:1;
|
unsigned int queue_log:1;
|
||||||
@@ -340,6 +341,8 @@ static void init_logger_chain(void)
|
|||||||
logfiles.event_log = ast_true(s);
|
logfiles.event_log = ast_true(s);
|
||||||
if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name")))
|
if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name")))
|
||||||
ast_copy_string(queue_log_name, s, sizeof(queue_log_name));
|
ast_copy_string(queue_log_name, s, sizeof(queue_log_name));
|
||||||
|
if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp")))
|
||||||
|
rotatetimestamp = ast_true(s);
|
||||||
|
|
||||||
AST_LIST_LOCK(&logchannels);
|
AST_LIST_LOCK(&logchannels);
|
||||||
var = ast_variable_browse(cfg, "logfiles");
|
var = ast_variable_browse(cfg, "logfiles");
|
||||||
@@ -405,6 +408,7 @@ int reload_logger(int rotate)
|
|||||||
if (rotate) {
|
if (rotate) {
|
||||||
ast_copy_string(old, f->filename, sizeof(old));
|
ast_copy_string(old, f->filename, sizeof(old));
|
||||||
|
|
||||||
|
if (!rotatetimestamp) {
|
||||||
for (x = 0; ; x++) {
|
for (x = 0; ; x++) {
|
||||||
snprintf(new, sizeof(new), "%s.%d", f->filename, x);
|
snprintf(new, sizeof(new), "%s.%d", f->filename, x);
|
||||||
myf = fopen((char *)new, "r");
|
myf = fopen((char *)new, "r");
|
||||||
@@ -413,6 +417,8 @@ int reload_logger(int rotate)
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
snprintf(new, sizeof(new), "%s.%ld", f->filename, (long)time(NULL));
|
||||||
|
|
||||||
/* do it */
|
/* do it */
|
||||||
if (rename(old,new))
|
if (rename(old,new))
|
||||||
@@ -428,6 +434,7 @@ int reload_logger(int rotate)
|
|||||||
if (logfiles.event_log) {
|
if (logfiles.event_log) {
|
||||||
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
|
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
|
||||||
if (event_rotate) {
|
if (event_rotate) {
|
||||||
|
if (!rotatetimestamp) {
|
||||||
for (x=0;;x++) {
|
for (x=0;;x++) {
|
||||||
snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
|
snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
|
||||||
myf = fopen((char *)new, "r");
|
myf = fopen((char *)new, "r");
|
||||||
@@ -436,6 +443,8 @@ int reload_logger(int rotate)
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
snprintf(new, sizeof(new), "%s/%s.%ld", (char *)ast_config_AST_LOG_DIR, EVENTLOG,(long)time(NULL));
|
||||||
|
|
||||||
/* do it */
|
/* do it */
|
||||||
if (rename(old,new))
|
if (rename(old,new))
|
||||||
@@ -456,6 +465,7 @@ int reload_logger(int rotate)
|
|||||||
if (logfiles.queue_log) {
|
if (logfiles.queue_log) {
|
||||||
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, queue_log_name);
|
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, queue_log_name);
|
||||||
if (queue_rotate) {
|
if (queue_rotate) {
|
||||||
|
if (!rotatetimestamp) {
|
||||||
for (x = 0; ; x++) {
|
for (x = 0; ; x++) {
|
||||||
snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, queue_log_name, x);
|
snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, queue_log_name, x);
|
||||||
myf = fopen((char *)new, "r");
|
myf = fopen((char *)new, "r");
|
||||||
@@ -465,6 +475,8 @@ int reload_logger(int rotate)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else
|
||||||
|
snprintf(new, sizeof(new), "%s/%s.%ld", (char *)ast_config_AST_LOG_DIR, queue_log_name,(long)time(NULL));
|
||||||
/* do it */
|
/* do it */
|
||||||
if (rename(old, new))
|
if (rename(old, new))
|
||||||
ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
|
ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
|
||||||
|
Reference in New Issue
Block a user