fix FSCORE-156
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8997 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
9229cfdf24
commit
0f873e692b
|
@ -16,6 +16,8 @@
|
|||
</cli-keybindings>
|
||||
|
||||
<settings>
|
||||
<!--Colorize the Console -->
|
||||
<param name="colorize-console" value="true"/>
|
||||
<!--Most channels to allow at once -->
|
||||
<param name="max-sessions" value="1000"/>
|
||||
<!--Most channels to create per second -->
|
||||
|
|
|
@ -195,6 +195,7 @@ struct switch_runtime {
|
|||
uint32_t default_dtmf_duration;
|
||||
switch_frame_t dummy_cng_frame;
|
||||
char dummy_data[5];
|
||||
switch_bool_t colorize_console;
|
||||
};
|
||||
|
||||
extern struct switch_runtime runtime;
|
||||
|
|
|
@ -74,7 +74,7 @@ typedef switch_status_t (*switch_log_function_t) (const switch_log_node_t *node,
|
|||
\param pool the memory pool to use
|
||||
\note to be called at application startup by the core
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_init(_In_ switch_memory_pool_t *pool);
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_init(_In_ switch_memory_pool_t *pool, _In_ switch_bool_t colorize);
|
||||
|
||||
/*!
|
||||
\brief Shut down the logging engine
|
||||
|
@ -104,7 +104,8 @@ SWITCH_DECLARE(void) switch_log_printf(_In_ switch_text_channel_t channel, _In_z
|
|||
\brief Shut down the logging engine
|
||||
\note to be called at application termination by the core
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(_In_ switch_log_function_t function, _In_ switch_log_level_t level);
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(_In_ switch_log_function_t function, _In_ switch_log_level_t level, _In_ switch_bool_t is_console);
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_unbind_logger(_In_ switch_log_function_t function);
|
||||
|
||||
/*!
|
||||
\brief Return the name of the specified log level
|
||||
|
|
|
@ -323,6 +323,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_socket_shutdown)
|
|||
|
||||
prefs.done = 1;
|
||||
|
||||
switch_log_unbind_logger(socket_logger);
|
||||
|
||||
close_socket(&listen_list.sock);
|
||||
|
||||
while (prefs.threads) {
|
||||
|
@ -1368,7 +1370,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
|
|||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
switch_log_bind_logger(socket_logger, SWITCH_LOG_DEBUG);
|
||||
switch_log_bind_logger(socket_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE);
|
||||
|
||||
|
||||
for (;;) {
|
||||
|
|
|
@ -42,7 +42,7 @@ static int COLORIZE = 0;
|
|||
static HANDLE hStdout;
|
||||
static WORD wOldColorAttrs;
|
||||
static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
||||
static WORD COLORS[] = { FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||
static WORD COLORS[] = { FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||
|
@ -53,7 +53,7 @@ static WORD COLORS[] = { FOREGROUND_RED | FOREGROUND_INTENSITY,
|
|||
FOREGROUND_GREEN | FOREGROUND_INTENSITY
|
||||
};
|
||||
#else
|
||||
static const char *COLORS[] = { SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN,
|
||||
static const char *COLORS[] = { SWITCH_SEQ_FWHITE, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN,
|
||||
SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW, ""
|
||||
};
|
||||
#endif
|
||||
|
@ -338,7 +338,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_console_load)
|
|||
|
||||
|
||||
/* setup my logger function */
|
||||
switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG);
|
||||
switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG, SWITCH_TRUE);
|
||||
|
||||
config_logger();
|
||||
RUNNING = 1;
|
||||
|
@ -348,10 +348,12 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_console_load)
|
|||
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_console_shutdown)
|
||||
{
|
||||
//switch_core_hash_destroy(&log_hash);
|
||||
//switch_core_hash_destroy(&name_hash);
|
||||
|
||||
switch_log_unbind_logger(switch_console_logger);
|
||||
switch_core_hash_destroy(&log_hash);
|
||||
|
||||
RUNNING = 0;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
return SWITCH_STATUS_UNLOAD;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
|
|
|
@ -374,9 +374,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
|
|||
switch_xml_free(xml);
|
||||
}
|
||||
|
||||
switch_log_bind_logger(mod_logfile_logger, SWITCH_LOG_DEBUG);
|
||||
switch_log_bind_logger(mod_logfile_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
return SWITCH_STATUS_NOUNLOAD;
|
||||
}
|
||||
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_logfile_shutdown)
|
||||
|
|
|
@ -152,7 +152,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_syslog_load)
|
|||
|
||||
openlog(globals.ident, LOG_PID, LOG_USER);
|
||||
|
||||
switch_log_bind_logger(mod_syslog_logger, SWITCH_LOG_DEBUG);
|
||||
switch_log_bind_logger(mod_syslog_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -160,6 +160,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_syslog_load)
|
|||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_syslog_shutdown)
|
||||
{
|
||||
closelog();
|
||||
switch_log_unbind_logger(mod_syslog_logger);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -896,7 +896,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
|
|||
switch_core_set_variable("local_ip_v6", guess_ip);
|
||||
switch_core_set_variable("base_dir", SWITCH_GLOBAL_dirs.base_dir);
|
||||
|
||||
switch_log_init(runtime.memory_pool);
|
||||
|
||||
switch_event_init(runtime.memory_pool);
|
||||
|
||||
if (switch_xml_init(runtime.memory_pool, err) != SWITCH_STATUS_SUCCESS) {
|
||||
|
@ -935,6 +935,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
|
|||
rlp.rlim_max = RLIM_INFINITY;
|
||||
setrlimit(RLIMIT_CORE, &rlp);
|
||||
#endif
|
||||
} else if (!strcasecmp(var, "colorize-console") && switch_true(val)) {
|
||||
runtime.colorize_console = SWITCH_TRUE;
|
||||
} else if (!strcasecmp(var, "mailer-app")) {
|
||||
runtime.mailer_app = switch_core_strdup(runtime.memory_pool, val);
|
||||
} else if (!strcasecmp(var, "mailer-app-args")) {
|
||||
|
@ -978,6 +980,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
|
|||
switch_xml_free(xml);
|
||||
}
|
||||
|
||||
switch_log_init(runtime.memory_pool, runtime.colorize_console);
|
||||
switch_core_state_machine_init(runtime.memory_pool);
|
||||
|
||||
*err = NULL;
|
||||
|
|
|
@ -48,6 +48,7 @@ static const char *LEVELS[] = {
|
|||
struct switch_log_binding {
|
||||
switch_log_function_t function;
|
||||
switch_log_level_t level;
|
||||
int is_console;
|
||||
struct switch_log_binding *next;
|
||||
};
|
||||
|
||||
|
@ -60,6 +61,29 @@ static switch_queue_t *LOG_QUEUE = NULL;
|
|||
static switch_queue_t *LOG_RECYCLE_QUEUE = NULL;
|
||||
static int8_t THREAD_RUNNING = 0;
|
||||
static uint8_t MAX_LEVEL = 0;
|
||||
static int mods_loaded = 0;
|
||||
static switch_bool_t COLORIZE = SWITCH_FALSE;
|
||||
|
||||
#ifdef WIN32
|
||||
static HANDLE hStdout;
|
||||
static WORD wOldColorAttrs;
|
||||
static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
||||
static WORD COLORS[] = { FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
|
||||
FOREGROUND_GREEN | FOREGROUND_INTENSITY
|
||||
};
|
||||
#else
|
||||
static const char *COLORS[] = { SWITCH_SEQ_FWHITE, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN,
|
||||
SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW, ""
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
SWITCH_DECLARE(const char *) switch_log_level2str(switch_log_level_t level)
|
||||
{
|
||||
|
@ -116,7 +140,33 @@ SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(const char *str)
|
|||
return level;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(switch_log_function_t function, switch_log_level_t level)
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_unbind_logger(switch_log_function_t function)
|
||||
{
|
||||
switch_log_binding_t *ptr = NULL, *last = NULL;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
|
||||
switch_mutex_lock(BINDLOCK);
|
||||
for (ptr = BINDINGS; ptr; ptr = ptr->next) {
|
||||
if (ptr->function == function) {
|
||||
if (last) {
|
||||
last->next = ptr->next;
|
||||
} else {
|
||||
BINDINGS = ptr->next;
|
||||
}
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
if (ptr->is_console) {
|
||||
mods_loaded--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
last = ptr;
|
||||
}
|
||||
switch_mutex_unlock(BINDLOCK);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(switch_log_function_t function, switch_log_level_t level, switch_bool_t is_console)
|
||||
{
|
||||
switch_log_binding_t *binding = NULL, *ptr = NULL;
|
||||
switch_assert(function != NULL);
|
||||
|
@ -131,6 +181,7 @@ SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(switch_log_function_t fun
|
|||
|
||||
binding->function = function;
|
||||
binding->level = level;
|
||||
binding->is_console = is_console;
|
||||
|
||||
switch_mutex_lock(BINDLOCK);
|
||||
for (ptr = BINDINGS; ptr && ptr->next; ptr = ptr->next);
|
||||
|
@ -140,6 +191,9 @@ SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(switch_log_function_t fun
|
|||
} else {
|
||||
BINDINGS = binding;
|
||||
}
|
||||
if (is_console) {
|
||||
mods_loaded++;
|
||||
}
|
||||
switch_mutex_unlock(BINDLOCK);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
@ -255,7 +309,7 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
|
|||
goto end;
|
||||
}
|
||||
|
||||
if (level == SWITCH_LOG_CONSOLE || !LOG_QUEUE || !THREAD_RUNNING) {
|
||||
if (level == SWITCH_LOG_CONSOLE || mods_loaded == 0 || !LOG_QUEUE || !THREAD_RUNNING) {
|
||||
if (handle) {
|
||||
int aok = 1;
|
||||
#ifndef WIN32
|
||||
|
@ -276,7 +330,11 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
|
|||
}
|
||||
#endif
|
||||
if (aok) {
|
||||
fprintf(handle, "%s", data);
|
||||
if (COLORIZE) {
|
||||
fprintf(handle, "%s%s%s", COLORS[level], data, SWITCH_SEQ_DEFAULT_COLOR);
|
||||
} else {
|
||||
fprintf(handle, "%s", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (level <= MAX_LEVEL) {
|
||||
|
@ -318,11 +376,11 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
|
|||
}
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool)
|
||||
SWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool, switch_bool_t colorize)
|
||||
{
|
||||
switch_thread_t *thread;
|
||||
switch_threadattr_t *thd_attr;;
|
||||
|
||||
|
||||
switch_assert(pool != NULL);
|
||||
|
||||
LOG_POOL = pool;
|
||||
|
@ -340,6 +398,20 @@ SWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool)
|
|||
while (!THREAD_RUNNING) {
|
||||
switch_yield(1000);
|
||||
}
|
||||
|
||||
if (colorize) {
|
||||
#ifdef WIN32
|
||||
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
|
||||
wOldColorAttrs = csbiInfo.wAttributes;
|
||||
COLORIZE = SWITCH_TRUE;
|
||||
}
|
||||
#else
|
||||
COLORIZE = SWITCH_TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue