change logger stuff and finalize mod_logfile

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6524 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-12-05 20:24:20 +00:00
parent aa4e109a18
commit b2dd6b51f5
6 changed files with 277 additions and 187 deletions

View File

@ -2,11 +2,14 @@
<!-- pick a file name, a function name or 'all' --> <!-- pick a file name, a function name or 'all' -->
<!-- map as many as you need for specific debugging --> <!-- map as many as you need for specific debugging -->
<mappings> <mappings>
<!-- <param name="log_event" value="DEBUG"/> --> <!--
<param name="all" value="DEBUG"/> name can be a file name, function name or 'all'
value is one or more of debug,info,notice,warning,error,crit,alert,all
-->
<map name="all" value="debug,info,notice,warning,error,crit,alert"/>
</mappings> </mappings>
<settings> <settings>
<!-- uncomment for color logging (for debugging) --> <!-- comment or set to false for no color logging -->
<!--<param name="colorize" value="true"/>--> <param name="colorize" value="true"/>
</settings> </settings>
</configuration> </configuration>

View File

@ -2,19 +2,22 @@
<settings> <settings>
<!-- true to auto rotate on HUP, false to open/close --> <!-- true to auto rotate on HUP, false to open/close -->
<param name="rotate" value="true"/> <param name="rotate" value="true"/>
</settings> </settings>
<profiles> <profiles>
<profile name="default"> <profile name="default">
<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 (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"/>-->
<!-- The level of the message to log -->
<!--<param name="level" value="debug,info,warning,notice,error,crit,alert"/>-->
<param name="level" value="all"/>
</settings> </settings>
<mappings>
<!--
name can be a file name, function name or 'all'
value is one or more of debug,info,notice,warning,error,crit,alert,all
-->
<map name="all" value="debug,info,notice,warning,error,crit,alert"/>
</mappings>
</profile> </profile>
</profiles> </profiles>
</configuration> </configuration>

View File

@ -117,6 +117,9 @@ SWITCH_DECLARE(const char *) switch_log_level2str(switch_log_level_t level);
*/ */
SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(const char *str); SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(const char *str);
SWITCH_DECLARE(uint32_t) switch_log_str2mask(const char *str);
#define switch_log_check_mask(_mask, _level) (_mask & (1 << _level))
///\} ///\}
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C
#endif #endif

View File

@ -35,7 +35,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_console_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_console_shutdown); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_console_shutdown);
SWITCH_MODULE_DEFINITION(mod_console, mod_console_load, mod_console_shutdown, NULL); SWITCH_MODULE_DEFINITION(mod_console, mod_console_load, mod_console_shutdown, NULL);
static const uint8_t STATIC_LEVELS[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
static int RUNNING = 0; static int RUNNING = 0;
static int COLORIZE = 0; static int COLORIZE = 0;
@ -61,34 +60,38 @@ static const char *COLORS[] = { SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRE
static switch_memory_pool_t *module_pool = NULL; static switch_memory_pool_t *module_pool = NULL;
static switch_hash_t *log_hash = NULL; static switch_hash_t *log_hash = NULL;
static switch_hash_t *name_hash = NULL; static uint32_t all_level = 0;
static int8_t all_level = -1; static int32_t hard_log_level = SWITCH_LOG_DEBUG;
static void del_mapping(char *var) static void del_mapping(char *var)
{ {
if (!strcasecmp(var, "all")) {
all_level = -1;
return;
}
switch_core_hash_insert(log_hash, var, NULL); switch_core_hash_insert(log_hash, var, NULL);
} }
static void add_mapping(char *var, char *val) static void add_mapping(char *var, char *val, int cumlative)
{ {
char *name; uint32_t m = 0;
if (cumlative) {
uint32_t l = switch_log_str2level(val);
int i;
assert(l < 10);
for (i = 0; i <= l; i++) {
m |= (1 << i);
}
} else {
m = switch_log_str2mask(val);
}
if (!strcasecmp(var, "all")) { if (!strcasecmp(var, "all")) {
all_level = (int8_t) switch_log_str2level(val); all_level |= m;
return; return;
} }
if (!(name = switch_core_hash_find(name_hash, var))) { del_mapping(var);
name = switch_core_strdup(module_pool, var); switch_core_hash_insert(log_hash, var, (void *)(intptr_t) m);
switch_core_hash_insert(name_hash, name, name);
}
del_mapping(name);
switch_core_hash_insert(log_hash, name, (void *) &STATIC_LEVELS[(uint8_t) switch_log_str2level(val)]);
} }
static switch_status_t config_logger(void) static switch_status_t config_logger(void)
@ -104,18 +107,19 @@ static switch_status_t config_logger(void)
if (log_hash) { if (log_hash) {
switch_core_hash_destroy(&log_hash); switch_core_hash_destroy(&log_hash);
} }
if (name_hash) {
switch_core_hash_destroy(&name_hash);
}
switch_core_hash_init(&log_hash, module_pool); switch_core_hash_init(&log_hash, module_pool);
switch_core_hash_init(&name_hash, module_pool);
if ((settings = switch_xml_child(cfg, "mappings"))) { if ((settings = switch_xml_child(cfg, "mappings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) { for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name"); char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value"); char *val = (char *) switch_xml_attr_soft(param, "value");
add_mapping(var, val, 1);
add_mapping(var, val); }
for (param = switch_xml_child(settings, "map"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
add_mapping(var, val, 0);
} }
} }
@ -146,30 +150,34 @@ static switch_status_t config_logger(void)
static switch_status_t switch_console_logger(const switch_log_node_t *node, switch_log_level_t level) static switch_status_t switch_console_logger(const switch_log_node_t *node, switch_log_level_t level)
{ {
FILE *handle; FILE *handle;
/*
if (!RUNNING) { if (!RUNNING) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_SUCCESS;
} }
*/
if (level > hard_log_level) {
return SWITCH_STATUS_SUCCESS;
}
if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) { if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) {
uint8_t *lookup = NULL; size_t mask = 0;
switch_log_level_t level = SWITCH_LOG_DEBUG; int ok = 0;
ok = switch_log_check_mask(all_level, level);
if (log_hash) { if (log_hash) {
lookup = switch_core_hash_find(log_hash, node->file); if (!ok) {
mask = (size_t) switch_core_hash_find(log_hash, node->file);
ok = switch_log_check_mask(mask, level);
}
if (!lookup) { if (!ok) {
lookup = switch_core_hash_find(log_hash, node->func); mask = (size_t) switch_core_hash_find(log_hash, node->func);
ok = switch_log_check_mask(mask, level);
} }
} }
if (lookup) { if (ok) {
level = (switch_log_level_t) *lookup;
} else if (all_level > -1) {
level = (switch_log_level_t) all_level;
}
if (!log_hash || (((all_level > -1) || lookup) && level >= node->level)) {
if (COLORIZE) { if (COLORIZE) {
#ifdef WIN32 #ifdef WIN32
SetConsoleTextAttribute(hStdout, COLORS[node->level]); SetConsoleTextAttribute(hStdout, COLORS[node->level]);
@ -190,13 +198,78 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_STANDARD_API(console_api_function)
{
int argc;
char *mydata = NULL, *argv[3];
const char *err = NULL;
if (!cmd) {
err = "bad args";
goto end;
}
mydata = strdup(cmd);
assert(mydata);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc > 0) {
if (argc < 2) {
err = "missing arg";
goto end;
}
if (!strcasecmp(argv[0], "loglevel")) {
int level;
if (*argv[1] > 47 && *argv[1] < 58) {
level = atoi(argv[1]);
} else {
level = switch_log_str2level(argv[1]);
}
hard_log_level = level;
stream->write_function(stream, "+OK console log level set to %s\n", switch_log_level2str(hard_log_level));
goto end;
} else if (!strcasecmp(argv[0], "colorize")) {
COLORIZE = switch_true(argv[1]);
stream->write_function(stream, "+OK console color %s\n", COLORIZE ? "enabled" : "disabled");
goto end;
}
err = "invalid command";
}
end:
if (err) {
stream->write_function(stream, "-Error %s\n", err);
}
free(mydata);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_console_load) SWITCH_MODULE_LOAD_FUNCTION(mod_console_load)
{ {
switch_api_interface_t *api_interface;
module_pool = pool; module_pool = pool;
/* 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);
SWITCH_ADD_API(api_interface, "console", "Console", console_api_function, "");
/* setup my logger function */ /* setup my logger function */
switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG); switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG);

View File

@ -39,11 +39,8 @@ SWITCH_MODULE_DEFINITION(mod_logfile, mod_logfile_load, mod_logfile_shutdown, NU
#define DEFAULT_LIMIT 0xA00000 /* About 10 MB */ #define DEFAULT_LIMIT 0xA00000 /* About 10 MB */
#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 switch_memory_pool_t *module_pool = NULL; static switch_memory_pool_t *module_pool = NULL;
static switch_hash_t *log_hash = NULL;
static switch_hash_t *name_hash = NULL;
static switch_hash_t *profile_hash = NULL; static switch_hash_t *profile_hash = NULL;
static struct { static struct {
@ -51,79 +48,35 @@ static struct {
switch_mutex_t *mutex; switch_mutex_t *mutex;
} globals; } globals;
struct level_set {
int level;
int on;
};
struct logfile_profile { 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 */
char *logfile; char *logfile;
switch_file_t *log_afd; switch_file_t *log_afd;
struct level_set levels[8]; switch_hash_t *log_hash;
uint32_t all_level;
}; };
typedef struct logfile_profile logfile_profile_t; typedef struct logfile_profile logfile_profile_t;
static logfile_profile_t *default_profile; static switch_status_t load_profile(switch_xml_t xml);
static switch_status_t load_profile(logfile_profile_t *profile, switch_xml_t xml); #if 0
static void del_mapping(char *var, logfile_profile_t *profile)
static void del_mapping(char *var)
{ {
switch_core_hash_insert(log_hash, var, NULL); switch_core_hash_insert(profile->log_hash, var, NULL);
} }
#endif
static void add_mapping(char *var, logfile_profile_t *profile) static void add_mapping(logfile_profile_t *profile, char *var, char *val)
{ {
char *name; if (!strcasecmp(var, "all")) {
profile->all_level |= (uint32_t) switch_log_str2mask(val);
if (!(name = switch_core_hash_find(name_hash, var))) { return;
name = switch_core_strdup(module_pool, var);
switch_core_hash_insert(name_hash, name, name);
} }
del_mapping(name); switch_core_hash_insert(profile->log_hash, var, (void *)(intptr_t) switch_log_str2mask(val));
switch_core_hash_insert(log_hash, name, (void *) profile);
}
void process_levels(logfile_profile_t *profile, char *p)
{
int x, i, argc = 0;
char *argv[10] = { 0 };
for (i=0; i < (sizeof(profile->levels) / sizeof(struct level_set)); i++) {
profile->levels[i].on = 0;
}
if ((argc = switch_separate_string(p, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
for (x = 0; x < argc; x++) {
if (!strncasecmp(argv[x], "alert", strlen(argv[x]))) {
profile->levels[SWITCH_LOG_ALERT].on = 1;
} else if (!strncasecmp(argv[x], "crit", strlen(argv[x]))) {
profile->levels[SWITCH_LOG_CRIT].on = 1;
} else if (!strncasecmp(argv[x], "error", strlen(argv[x]))) {
profile->levels[SWITCH_LOG_ERROR].on = 1;
} else if (!strncasecmp(argv[x], "warn", strlen(argv[x]))) {
profile->levels[SWITCH_LOG_WARNING].on = 1;
} else if (!strncasecmp(argv[x], "notice", strlen(argv[x]))) {
profile->levels[SWITCH_LOG_NOTICE].on = 1;
} else if (!strncasecmp(argv[x], "info", strlen(argv[x]))) {
profile->levels[SWITCH_LOG_INFO].on = 1;
} else if (!strncasecmp(argv[x], "debug", strlen(argv[x]))) {
profile->levels[SWITCH_LOG_DEBUG].on = 1;
} else if (!strncasecmp(argv[x], "console", strlen(argv[x]))) {
profile->levels[SWITCH_LOG_CONSOLE].on = 1;
} else if (!strncasecmp(argv[x], "all", strlen(argv[x]))) {
for (i=0; i < (sizeof(profile->levels) / sizeof(struct level_set)); i++) {
profile->levels[i].on = 1;
}
}
}
}
return;
} }
static switch_status_t mod_logfile_rotate(logfile_profile_t *profile); static switch_status_t mod_logfile_rotate(logfile_profile_t *profile);
@ -198,7 +151,10 @@ static switch_status_t mod_logfile_rotate(logfile_profile_t *profile)
switch_file_close(profile->log_afd); switch_file_close(profile->log_afd);
switch_file_rename(profile->logfile, p, pool); switch_file_rename(profile->logfile, p, pool);
mod_logfile_openlogfile(profile, SWITCH_FALSE); if ((status = mod_logfile_openlogfile(profile, SWITCH_FALSE)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Rotating Log!\n");
goto end;
}
break; break;
} }
@ -219,81 +175,124 @@ end:
static switch_status_t mod_logfile_raw_write(logfile_profile_t *profile, char *log_data) static switch_status_t mod_logfile_raw_write(logfile_profile_t *profile, char *log_data)
{ {
switch_size_t len; switch_size_t len;
switch_status_t status = SWITCH_STATUS_SUCCESS;
len = strlen(log_data); len = strlen(log_data);
if (len <= 0) { if (len <= 0 || !profile->log_afd) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
switch_mutex_lock(globals.mutex); switch_mutex_lock(globals.mutex);
/* TODO: handle null log_afd */
if (switch_file_write(profile->log_afd, log_data, &len) != SWITCH_STATUS_SUCCESS) { if (switch_file_write(profile->log_afd, log_data, &len) != SWITCH_STATUS_SUCCESS) {
switch_file_close(profile->log_afd); switch_file_close(profile->log_afd);
mod_logfile_openlogfile(profile, SWITCH_TRUE); if ((status = mod_logfile_openlogfile(profile, SWITCH_TRUE)) == SWITCH_STATUS_SUCCESS) {
len = strlen(log_data); len = strlen(log_data);
switch_file_write(profile->log_afd, log_data, &len); switch_file_write(profile->log_afd, log_data, &len);
}
} }
switch_mutex_unlock(globals.mutex); switch_mutex_unlock(globals.mutex);
profile->log_size += len; if (status == SWITCH_STATUS_SUCCESS) {
profile->log_size += len;
if (profile->roll_size && profile->log_size >= profile->roll_size) { if (profile->roll_size && profile->log_size >= profile->roll_size) {
mod_logfile_rotate(profile); mod_logfile_rotate(profile);
} }
}
return status;
}
static switch_status_t process_node(const switch_log_node_t *node, switch_log_level_t level)
{
switch_hash_index_t *hi;
void *val;
const void *var;
logfile_profile_t *profile;
for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
size_t mask = 0;
int ok = 0;
switch_hash_this(hi, &var, NULL, &val);
profile = val;
ok = switch_log_check_mask(profile->all_level, level);
if (!ok) {
mask = (size_t) switch_core_hash_find(profile->log_hash, node->file);
ok = switch_log_check_mask(mask, level);
}
if (!ok) {
mask = (size_t) switch_core_hash_find(profile->log_hash, node->func);
ok = switch_log_check_mask(mask, level);
}
if (ok) {
mod_logfile_raw_write(profile, node->data);
}
}
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t mod_logfile_logger(const switch_log_node_t *node, switch_log_level_t level) static switch_status_t mod_logfile_logger(const switch_log_node_t *node, switch_log_level_t level)
{ {
/* TODO: Handle multiple profiles */ return process_node(node, level);
if (default_profile->levels[node->level].on) {
mod_logfile_raw_write(default_profile, node->data);
}
return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t load_profile(logfile_profile_t *profile, switch_xml_t xml) static switch_status_t load_profile(switch_xml_t xml)
{ {
switch_xml_t param; switch_xml_t param, settings;
char *name = (char *) switch_xml_attr_soft(xml, "name");
logfile_profile_t *new_profile;
profile->levels[0].level = SWITCH_LOG_CONSOLE; new_profile = switch_core_alloc(module_pool, sizeof(*new_profile));
profile->levels[1].level = SWITCH_LOG_ALERT; memset(new_profile, 0, sizeof(*new_profile));
profile->levels[2].level = SWITCH_LOG_CRIT; switch_core_hash_init(&(new_profile->log_hash), module_pool);
profile->levels[3].level = SWITCH_LOG_ERROR; new_profile->name = switch_core_strdup(module_pool, switch_str_nil(name));
profile->levels[4].level = SWITCH_LOG_WARNING;
profile->levels[5].level = SWITCH_LOG_NOTICE;
profile->levels[6].level = SWITCH_LOG_INFO;
profile->levels[7].level = SWITCH_LOG_DEBUG;
for (param = switch_xml_child(xml, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name"); if ((settings = switch_xml_child(xml, "settings"))) {
char *val = (char *) switch_xml_attr_soft(param, "value"); for (param = switch_xml_child(settings, "map"); param; param = param->next) {
if (!strcmp(var, "logfile")) { char *var = (char *) switch_xml_attr_soft(param, "name");
profile->logfile = strdup(val); char *val = (char *) switch_xml_attr_soft(param, "value");
} else if (!strcmp(var, "level")) { if (!strcmp(var, "logfile")) {
process_levels(profile, val); new_profile->logfile = strdup(val);
} else if (!strcmp(var, "rollover")) { } else if (!strcmp(var, "rollover")) {
profile->roll_size = atoi(val); new_profile->roll_size = atoi(val);
if (profile->roll_size < 0) { if (new_profile->roll_size < 0) {
profile->roll_size = 0; new_profile->roll_size = 0;
} }
}
}
}
if ((settings = switch_xml_child(xml, "mappings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
add_mapping(new_profile, var, val);
} }
} }
if (switch_strlen_zero(profile->logfile)) { if (switch_strlen_zero(new_profile->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");
profile->logfile = strdup(logfile); new_profile->logfile = strdup(logfile);
} }
/* TODO: add mapping parsing from config */ if (mod_logfile_openlogfile(new_profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
add_mapping("all", profile); return SWITCH_STATUS_GENERR;
}
return 0; switch_core_hash_insert(profile_hash, new_profile->name, (void *) new_profile);
return SWITCH_STATUS_SUCCESS;
} }
@ -318,7 +317,9 @@ static void event_handler(switch_event_t *event)
switch_hash_this(hi, &var, NULL, &val); switch_hash_this(hi, &var, NULL, &val);
profile = val; profile = val;
switch_file_close(profile->log_afd); switch_file_close(profile->log_afd);
mod_logfile_openlogfile(profile, SWITCH_TRUE); if (mod_logfile_openlogfile(profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Re-opening Log!\n");
}
} }
switch_mutex_unlock(globals.mutex); switch_mutex_unlock(globals.mutex);
} }
@ -335,17 +336,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
if (log_hash) {
switch_core_hash_destroy(&log_hash);
}
if (name_hash) {
switch_core_hash_destroy(&name_hash);
}
if (profile_hash) { if (profile_hash) {
switch_core_hash_destroy(&profile_hash); switch_core_hash_destroy(&profile_hash);
} }
switch_core_hash_init(&log_hash, module_pool);
switch_core_hash_init(&name_hash, module_pool);
switch_core_hash_init(&profile_hash, module_pool); switch_core_hash_init(&profile_hash, module_pool);
if (switch_event_bind((char *) modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) { if (switch_event_bind((char *) modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
@ -368,26 +361,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
} }
} }
} }
if ((profiles = switch_xml_child(cfg, "profiles"))) { if ((profiles = switch_xml_child(cfg, "profiles"))) {
for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) { for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) {
char *name = (char *) switch_xml_attr_soft(xprofile, "name"); if (load_profile(xprofile) != SWITCH_STATUS_SUCCESS) {
if (!(settings = switch_xml_child(xprofile, "settings"))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error loading profile.");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Settings, check the new config!\n"); }
} else { }
logfile_profile_t *profile; }
profile = switch_core_alloc(module_pool, sizeof(*profile));
memset(profile, 0, sizeof(*profile));
profile->name = switch_core_strdup(module_pool, switch_str_nil(name));
load_profile(profile, settings);
switch_core_hash_insert(profile_hash, profile->name, (void *) profile);
if (mod_logfile_openlogfile(profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}
/* TODO: remove default_profile */
default_profile = profile;
}
}
}
switch_xml_free(xml); switch_xml_free(xml);
} }

View File

@ -69,6 +69,33 @@ SWITCH_DECLARE(const char *) switch_log_level2str(switch_log_level_t level)
return LEVELS[level]; return LEVELS[level];
} }
SWITCH_DECLARE(uint32_t) switch_log_str2mask(const char *str)
{
int argc = 0, x = 0;
char *argv[10] = { 0 };
uint32_t mask = 0;
char *p = strdup(str);
assert(p);
if ((argc = switch_separate_string(p, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
for (x = 0; x < argc; x++) {
if (!strcasecmp(argv[x], "all")) {
mask = 0xFF;
break;
} else {
mask |= (1 << switch_log_str2level(argv[x]));
}
}
}
free(p);
return mask;
}
SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(const char *str) SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(const char *str)
{ {
int x = 0; int x = 0;