update logger stuff
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6510 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
7b34d76091
commit
a1e9233eff
|
@ -2,7 +2,9 @@
|
||||||
<settings>
|
<settings>
|
||||||
<!-- File to log to -->
|
<!-- File to log to -->
|
||||||
<!--<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 -->
|
<!-- true to auto rotate on HUP, false to open/close -->
|
||||||
|
<param name="rotate" value="true"/>
|
||||||
|
<!-- At this length in bytes rotate the log file (0 for never) -->
|
||||||
<!--<param name="rollover" value="10485760"/>-->
|
<!--<param name="rollover" value="10485760"/>-->
|
||||||
<!-- The level of the message to log -->
|
<!-- The level of the message to log -->
|
||||||
<!--<param name="level" value="debug,info,warning,notice,error,crit,alert"/>-->
|
<!--<param name="level" value="debug,info,warning,notice,error,crit,alert"/>-->
|
||||||
|
|
|
@ -49,6 +49,8 @@ static struct {
|
||||||
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 */
|
||||||
char *logfile;
|
char *logfile;
|
||||||
|
int rotate;
|
||||||
|
switch_mutex_t *mutex;
|
||||||
switch_file_t *log_afd;
|
switch_file_t *log_afd;
|
||||||
} globals;
|
} globals;
|
||||||
|
|
||||||
|
@ -126,7 +128,7 @@ static switch_status_t mod_logfile_openlogfile(switch_bool_t check)
|
||||||
|
|
||||||
globals.log_size = switch_file_get_size(globals.log_afd);
|
globals.log_size = switch_file_get_size(globals.log_afd);
|
||||||
|
|
||||||
if (check && globals.log_size >= globals.roll_size) {
|
if (check && globals.roll_size && globals.log_size >= globals.roll_size) {
|
||||||
mod_logfile_rotate();
|
mod_logfile_rotate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +146,9 @@ static switch_status_t mod_logfile_rotate(void)
|
||||||
switch_time_exp_t tm;
|
switch_time_exp_t tm;
|
||||||
char date[80] = "";
|
char date[80] = "";
|
||||||
switch_size_t retsize;
|
switch_size_t retsize;
|
||||||
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
|
switch_mutex_lock(globals.mutex);
|
||||||
|
|
||||||
switch_time_exp_lt(&tm, switch_time_now());
|
switch_time_exp_lt(&tm, switch_time_now());
|
||||||
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
|
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
|
||||||
|
@ -152,8 +157,11 @@ static switch_status_t mod_logfile_rotate(void)
|
||||||
|
|
||||||
stat = switch_file_seek(globals.log_afd, SWITCH_SEEK_SET, &offset);
|
stat = switch_file_seek(globals.log_afd, SWITCH_SEEK_SET, &offset);
|
||||||
|
|
||||||
if (stat != SWITCH_STATUS_SUCCESS)
|
if (stat != SWITCH_STATUS_SUCCESS) {
|
||||||
return SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
p = malloc(strlen(globals.logfile)+WARM_FUZZY_OFFSET);
|
p = malloc(strlen(globals.logfile)+WARM_FUZZY_OFFSET);
|
||||||
assert(p);
|
assert(p);
|
||||||
|
@ -178,7 +186,13 @@ static switch_status_t mod_logfile_rotate(void)
|
||||||
|
|
||||||
switch_core_destroy_memory_pool(&pool);
|
switch_core_destroy_memory_pool(&pool);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New log started.\n");
|
||||||
|
|
||||||
|
end:
|
||||||
|
|
||||||
|
switch_mutex_unlock(globals.mutex);
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write to the actual logfile */
|
/* write to the actual logfile */
|
||||||
|
@ -187,17 +201,24 @@ static switch_status_t mod_logfile_raw_write(char *log_data)
|
||||||
switch_size_t len;
|
switch_size_t len;
|
||||||
len = strlen(log_data);
|
len = strlen(log_data);
|
||||||
|
|
||||||
if (len <= 0)
|
if (len <= 0) {
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_mutex_lock(globals.mutex);
|
||||||
|
|
||||||
if (switch_file_write(globals.log_afd, log_data, &len) != SWITCH_STATUS_SUCCESS) {
|
if (switch_file_write(globals.log_afd, log_data, &len) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_file_close(globals.log_afd);
|
switch_file_close(globals.log_afd);
|
||||||
mod_logfile_openlogfile(SWITCH_TRUE);
|
mod_logfile_openlogfile(SWITCH_TRUE);
|
||||||
|
len = strlen(log_data);
|
||||||
|
switch_file_write(globals.log_afd, log_data, &len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch_mutex_unlock(globals.mutex);
|
||||||
|
|
||||||
globals.log_size += len;
|
globals.log_size += len;
|
||||||
|
|
||||||
if (globals.log_size >= globals.roll_size) {
|
if (globals.roll_size && globals.log_size >= globals.roll_size) {
|
||||||
mod_logfile_rotate();
|
mod_logfile_rotate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,18 +249,21 @@ static switch_status_t load_config(void)
|
||||||
char *val = (char *) switch_xml_attr_soft(param, "value");
|
char *val = (char *) switch_xml_attr_soft(param, "value");
|
||||||
if (!strcmp(var, "logfile")) {
|
if (!strcmp(var, "logfile")) {
|
||||||
set_global_logfile(val);
|
set_global_logfile(val);
|
||||||
|
} else if (!strcmp(var, "rotate")) {
|
||||||
|
globals.rotate = switch_true(val);
|
||||||
} else if (!strcmp(var, "level")) {
|
} else if (!strcmp(var, "level")) {
|
||||||
process_levels(val);
|
process_levels(val);
|
||||||
} else if (!strcmp(var, "rollover")) {
|
} else if (!strcmp(var, "rollover")) {
|
||||||
globals.roll_size = atoi(val);
|
globals.roll_size = atoi(val);
|
||||||
|
if (globals.roll_size < 0) {
|
||||||
|
globals.roll_size = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch_xml_free(xml);
|
switch_xml_free(xml);
|
||||||
}
|
}
|
||||||
if (globals.roll_size == 0) {
|
|
||||||
globals.roll_size = DEFAULT_LIMIT;
|
|
||||||
}
|
|
||||||
if (switch_strlen_zero(globals.logfile)) {
|
if (switch_strlen_zero(globals.logfile)) {
|
||||||
char logfile[512];
|
char logfile[512];
|
||||||
snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "freeswitch.log");
|
snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "freeswitch.log");
|
||||||
|
@ -249,11 +273,37 @@ static switch_status_t load_config(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void event_handler(switch_event_t *event)
|
||||||
|
{
|
||||||
|
const char *sig = switch_event_get_header(event, "Trapped-Signal");
|
||||||
|
|
||||||
|
if (sig && !strcmp(sig, "HUP")) {
|
||||||
|
if (globals.rotate) {
|
||||||
|
mod_logfile_rotate();
|
||||||
|
} else {
|
||||||
|
switch_mutex_lock(globals.mutex);
|
||||||
|
switch_file_close(globals.log_afd);
|
||||||
|
mod_logfile_openlogfile(SWITCH_TRUE);
|
||||||
|
switch_mutex_unlock(globals.mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
|
SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
|
||||||
{
|
{
|
||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
|
|
||||||
module_pool = pool;
|
module_pool = pool;
|
||||||
|
memset(&globals, 0, sizeof(globals));
|
||||||
|
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
|
||||||
|
|
||||||
|
if (switch_event_bind((char *) modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
|
||||||
|
return SWITCH_STATUS_GENERR;
|
||||||
|
}
|
||||||
|
|
||||||
/* connect my internal structure to the blank pointer passed to me */
|
/* connect my internal structure to the blank pointer passed to me */
|
||||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||||
|
|
|
@ -62,7 +62,7 @@ static HANDLE shutdown_event;
|
||||||
/* signal handler for when freeswitch is running in background mode.
|
/* signal handler for when freeswitch is running in background mode.
|
||||||
* signal triggers the shutdown of freeswitch
|
* signal triggers the shutdown of freeswitch
|
||||||
*/
|
*/
|
||||||
static void handle_SIGHUP(int sig)
|
static void handle_SIGTERM(int sig)
|
||||||
{
|
{
|
||||||
int32_t arg = 0;
|
int32_t arg = 0;
|
||||||
if (sig);
|
if (sig);
|
||||||
|
@ -390,11 +390,9 @@ int main(int argc, char *argv[])
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signal(SIGTERM, handle_SIGTERM);
|
||||||
|
|
||||||
if (nc) {
|
if (nc) {
|
||||||
|
|
||||||
signal(SIGHUP, handle_SIGHUP);
|
|
||||||
signal(SIGTERM, handle_SIGHUP);
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue