mod_logfile code/default config cleanup

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6507 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-12-04 23:06:39 +00:00
parent 3e51067b53
commit c26098bac2
2 changed files with 5 additions and 45 deletions

View File

@ -1,15 +1,12 @@
<configuration name="logfile.conf" description="File Logging"> <configuration name="logfile.conf" description="File Logging">
<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 --> <!-- At this length in bytes rotate the log file -->
<param name="rollover" value="12000"/> <!--<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"/>-->
<param name="level" value="all"/> <param name="level" value="all"/>
<!-- Format of the log messages -->
<!-- ${time} ${file} ${func} ${message} -->
<param name="format" value="${time} ${file} ${func} ${message}"/>
</settings> </settings>
</configuration> </configuration>

View File

@ -36,8 +36,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_logfile_shutdown); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_logfile_shutdown);
SWITCH_MODULE_DEFINITION(mod_logfile, mod_logfile_load, mod_logfile_shutdown, NULL); SWITCH_MODULE_DEFINITION(mod_logfile, mod_logfile_load, mod_logfile_shutdown, NULL);
#define DEFAULT_FORMAT "${data}" #define DEFAULT_LIMIT 0xA00000 /* About 10 MB */
#define DEFAULT_LIMIT 0x7FFFFFFF
#define WARM_FUZZY_OFFSET 256 #define WARM_FUZZY_OFFSET 256
#define MAX_ROT 4096 /* why not */ #define MAX_ROT 4096 /* why not */
static const uint8_t STATIC_LEVELS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; static const uint8_t STATIC_LEVELS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
@ -50,12 +49,10 @@ 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;
char *format;
switch_file_t *log_afd; switch_file_t *log_afd;
} globals; } globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_logfile, globals.logfile); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_logfile, globals.logfile);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_format, globals.format);
/* i know this is strange but it's the fastest way i could think of managing log levels. */ /* i know this is strange but it's the fastest way i could think of managing log levels. */
/* i'd rather not try to search something each time we get a message to log */ /* i'd rather not try to search something each time we get a message to log */
@ -136,7 +133,6 @@ static switch_status_t mod_logfile_openlogfile(switch_bool_t check)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
/* rotate the log file */ /* rotate the log file */
static switch_status_t mod_logfile_rotate(void) static switch_status_t mod_logfile_rotate(void)
{ {
@ -179,41 +175,12 @@ static switch_status_t mod_logfile_rotate(void)
} }
free(p); free(p);
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
#if 0
/* write to the actual logfile */
static switch_status_t mod_logfile_write(char *fmt, ...)
{
char *log_data;
switch_status_t stat;
switch_size_t len;
va_list args;
va_start(args, fmt);
len = switch_vasprintf(&log_data, fmt, args);
if (len <= 0)
return SWITCH_STATUS_FALSE;
stat = switch_file_write(globals.log_afd, log_data, &len);
globals.log_size += len;
if (globals.log_size >= globals.roll_size) {
mod_logfile_rotate();
}
return SWITCH_STATUS_SUCCESS;
}
#endif
/* write to the actual logfile */ /* write to the actual logfile */
static switch_status_t mod_logfile_raw_write(char *log_data) static switch_status_t mod_logfile_raw_write(char *log_data)
{ {
@ -261,8 +228,6 @@ 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, "format")) {
set_global_format(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")) {
@ -280,9 +245,7 @@ static switch_status_t load_config(void)
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");
set_global_logfile(logfile); set_global_logfile(logfile);
} }
if (switch_strlen_zero(globals.format)) {
set_global_format(DEFAULT_FORMAT);
}
return 0; return 0;
} }