FS-3763 --resolve
This commit is contained in:
parent
7987d0461c
commit
2d4e159bef
|
@ -10,6 +10,9 @@
|
||||||
<!--<param name="logfile" value="/var/log/freeswitch.log"/>-->
|
<!--<param name="logfile" value="/var/log/freeswitch.log"/>-->
|
||||||
<!-- At this length in bytes rotate the log file (0 for never) -->
|
<!-- At this length in bytes rotate the log file (0 for never) -->
|
||||||
<param name="rollover" value="10485760"/>
|
<param name="rollover" value="10485760"/>
|
||||||
|
<!-- Maximum number of log files to keep before wrapping -->
|
||||||
|
<!-- If this parameter is enabled, the log filenames will not include a date stamp -->
|
||||||
|
<!-- <param name="maximum-rotate" value="32"/> -->
|
||||||
<!-- Uncomment to prefix all log lines by the session's uuid -->
|
<!-- Uncomment to prefix all log lines by the session's uuid -->
|
||||||
<!-- <param name="uuid" value="true" /> -->
|
<!-- <param name="uuid" value="true" /> -->
|
||||||
</settings>
|
</settings>
|
||||||
|
|
|
@ -53,10 +53,12 @@ struct logfile_profile {
|
||||||
char *name;
|
char *name;
|
||||||
switch_size_t log_size; /* keep the log size in check for rotation */
|
switch_size_t log_size; /* keep the log size in check for rotation */
|
||||||
switch_size_t roll_size; /* the size that we want to rotate the file at */
|
switch_size_t roll_size; /* the size that we want to rotate the file at */
|
||||||
|
switch_size_t max_rot; /* number of log files to keep within the rotation */
|
||||||
char *logfile;
|
char *logfile;
|
||||||
switch_file_t *log_afd;
|
switch_file_t *log_afd;
|
||||||
switch_hash_t *log_hash;
|
switch_hash_t *log_hash;
|
||||||
uint32_t all_level;
|
uint32_t all_level;
|
||||||
|
uint32_t suffix; /* suffix of the highest logfile name */
|
||||||
switch_bool_t log_uuid;
|
switch_bool_t log_uuid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -140,6 +142,58 @@ static switch_status_t mod_logfile_rotate(logfile_profile_t *profile)
|
||||||
switch_core_new_memory_pool(&pool);
|
switch_core_new_memory_pool(&pool);
|
||||||
filename = switch_core_alloc(pool, strlen(profile->logfile) + WARM_FUZZY_OFFSET);
|
filename = switch_core_alloc(pool, strlen(profile->logfile) + WARM_FUZZY_OFFSET);
|
||||||
|
|
||||||
|
if (profile->max_rot) {
|
||||||
|
char *from_filename = NULL;
|
||||||
|
char *to_filename = NULL;
|
||||||
|
|
||||||
|
from_filename = switch_core_alloc(pool, strlen(profile->logfile) + WARM_FUZZY_OFFSET);
|
||||||
|
to_filename = switch_core_alloc(pool, strlen(profile->logfile) + WARM_FUZZY_OFFSET);
|
||||||
|
|
||||||
|
for (i=profile->suffix; i>1; i--) {
|
||||||
|
sprintf((char *) to_filename, "%s.%i", profile->logfile, i);
|
||||||
|
sprintf((char *) from_filename, "%s.%i", profile->logfile, i-1);
|
||||||
|
|
||||||
|
if (switch_file_exists(to_filename, pool) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
if ((status = switch_file_remove(to_filename, pool)) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error removing log %s\n",to_filename);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status = switch_file_rename(from_filename, to_filename, pool)) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error renaming log from %s to %s\n",from_filename, to_filename);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf((char *) to_filename, "%s.%i", profile->logfile, i);
|
||||||
|
|
||||||
|
if (switch_file_exists(to_filename, pool) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
if ((status = switch_file_remove(to_filename, pool)) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error removing log %s\n",to_filename);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_file_close(profile->log_afd);
|
||||||
|
if ((status = switch_file_rename(profile->logfile, to_filename, pool)) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error renaming log from %s to %s\n", profile->logfile, to_filename);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status = mod_logfile_openlogfile(profile, SWITCH_FALSE)) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error reopening log %s\n",profile->logfile);
|
||||||
|
}
|
||||||
|
if (profile->suffix < profile->max_rot) {
|
||||||
|
profile->suffix++;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New log started.\n");
|
||||||
|
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* XXX This have no real value EXCEPT making sure if we rotate within the same second, the end index will increase */
|
||||||
for (i = 1; i < MAX_ROT; i++) {
|
for (i = 1; i < MAX_ROT; i++) {
|
||||||
sprintf((char *) filename, "%s.%s.%i", profile->logfile, date, i);
|
sprintf((char *) filename, "%s.%s.%i", profile->logfile, date, i);
|
||||||
if (switch_file_exists(filename, pool) == SWITCH_STATUS_SUCCESS) {
|
if (switch_file_exists(filename, pool) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
@ -269,6 +323,7 @@ static switch_status_t load_profile(switch_xml_t xml)
|
||||||
switch_core_hash_init(&(new_profile->log_hash), module_pool);
|
switch_core_hash_init(&(new_profile->log_hash), module_pool);
|
||||||
new_profile->name = switch_core_strdup(module_pool, switch_str_nil(name));
|
new_profile->name = switch_core_strdup(module_pool, switch_str_nil(name));
|
||||||
|
|
||||||
|
new_profile->suffix = 1;
|
||||||
|
|
||||||
if ((settings = switch_xml_child(xml, "settings"))) {
|
if ((settings = switch_xml_child(xml, "settings"))) {
|
||||||
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
||||||
|
@ -281,6 +336,11 @@ static switch_status_t load_profile(switch_xml_t xml)
|
||||||
if (new_profile->roll_size < 0) {
|
if (new_profile->roll_size < 0) {
|
||||||
new_profile->roll_size = 0;
|
new_profile->roll_size = 0;
|
||||||
}
|
}
|
||||||
|
} else if (!strcmp(var, "maximum-rotate")) {
|
||||||
|
new_profile->max_rot = atoi(val);
|
||||||
|
if (new_profile->max_rot < 0) {
|
||||||
|
new_profile->max_rot = MAX_ROT;
|
||||||
|
}
|
||||||
} else if (!strcmp(var, "uuid") && switch_true(val)) {
|
} else if (!strcmp(var, "uuid") && switch_true(val)) {
|
||||||
new_profile->log_uuid = SWITCH_TRUE;
|
new_profile->log_uuid = SWITCH_TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue