2006-04-11 21:13:44 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2012-04-18 11:51:48 -05:00
|
|
|
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
|
2006-04-11 21:13:44 +00:00
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-04-11 21:13:44 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-04-11 21:13:44 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* mod_console.c -- Console Logger
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <switch.h>
|
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_console_load);
|
2007-09-29 01:06:08 +00:00
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_console_shutdown);
|
|
|
|
SWITCH_MODULE_DEFINITION(mod_console, mod_console_load, mod_console_shutdown, NULL);
|
2007-06-13 17:06:10 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
static int RUNNING = 0;
|
|
|
|
|
2007-02-28 18:28:07 +00:00
|
|
|
static int COLORIZE = 0;
|
2007-03-04 22:19:39 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
static HANDLE hStdout;
|
2007-03-24 03:32:24 +00:00
|
|
|
static WORD wOldColorAttrs;
|
|
|
|
static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
2008-07-14 17:09:47 +00:00
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
static WORD
|
2007-03-24 03:32:24 +00:00
|
|
|
#else
|
2010-02-06 03:38:24 +00:00
|
|
|
static const char *
|
2007-03-04 22:19:39 +00:00
|
|
|
#endif
|
2010-02-06 03:38:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COLORS[] =
|
|
|
|
{ SWITCH_SEQ_DEFAULT_COLOR, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN, SWITCH_SEQ_FGREEN,
|
|
|
|
SWITCH_SEQ_FYELLOW };
|
2008-07-14 17:09:47 +00:00
|
|
|
|
2006-04-11 21:13:44 +00:00
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
static switch_memory_pool_t *module_pool = NULL;
|
|
|
|
static switch_hash_t *log_hash = NULL;
|
2007-12-05 20:24:20 +00:00
|
|
|
static uint32_t all_level = 0;
|
|
|
|
static int32_t hard_log_level = SWITCH_LOG_DEBUG;
|
2008-02-20 20:15:45 +00:00
|
|
|
//static int32_t failed_write = 0;
|
2007-03-29 22:31:56 +00:00
|
|
|
static void del_mapping(char *var)
|
|
|
|
{
|
2006-04-12 18:53:42 +00:00
|
|
|
switch_core_hash_insert(log_hash, var, NULL);
|
|
|
|
}
|
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
static void add_mapping(char *var, char *val, int cumlative)
|
2006-04-12 18:53:42 +00:00
|
|
|
{
|
2007-12-05 20:24:20 +00:00
|
|
|
uint32_t m = 0;
|
|
|
|
|
|
|
|
if (cumlative) {
|
|
|
|
uint32_t l = switch_log_str2level(val);
|
2007-12-06 13:50:14 +00:00
|
|
|
uint32_t i;
|
2006-04-12 18:53:42 +00:00
|
|
|
|
2007-12-10 19:16:50 +00:00
|
|
|
if (l < 10) {
|
|
|
|
for (i = 0; i <= l; i++) {
|
|
|
|
m |= (1 << i);
|
|
|
|
}
|
2007-12-05 20:24:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m = switch_log_str2mask(val);
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2006-04-12 19:10:04 +00:00
|
|
|
if (!strcasecmp(var, "all")) {
|
2008-07-15 17:54:13 +00:00
|
|
|
all_level = m | switch_log_str2mask("console");
|
2006-04-12 19:10:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
del_mapping(var);
|
2008-05-27 04:54:52 +00:00
|
|
|
switch_core_hash_insert(log_hash, var, (void *) (intptr_t) m);
|
2006-04-12 18:53:42 +00:00
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t config_logger(void)
|
2006-04-12 17:51:47 +00:00
|
|
|
{
|
|
|
|
char *cf = "console.conf";
|
2006-05-10 03:23:05 +00:00
|
|
|
switch_xml_t cfg, xml, settings, param;
|
2006-04-12 17:51:47 +00:00
|
|
|
|
2006-05-10 15:47:54 +00:00
|
|
|
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
2008-10-11 06:19:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
|
2006-05-10 03:23:05 +00:00
|
|
|
return SWITCH_STATUS_TERM;
|
2006-04-12 17:51:47 +00:00
|
|
|
}
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
if (log_hash) {
|
|
|
|
switch_core_hash_destroy(&log_hash);
|
|
|
|
}
|
2007-12-05 20:24:20 +00:00
|
|
|
|
2006-04-12 17:51:47 +00:00
|
|
|
switch_core_hash_init(&log_hash, module_pool);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-05-10 03:23:05 +00:00
|
|
|
if ((settings = switch_xml_child(cfg, "mappings"))) {
|
|
|
|
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
2006-05-17 00:58:21 +00:00
|
|
|
char *var = (char *) switch_xml_attr_soft(param, "name");
|
|
|
|
char *val = (char *) switch_xml_attr_soft(param, "value");
|
2007-12-05 20:24:20 +00:00
|
|
|
add_mapping(var, val, 1);
|
|
|
|
}
|
|
|
|
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);
|
2006-04-12 17:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-10 03:23:05 +00:00
|
|
|
|
2007-02-28 18:28:07 +00:00
|
|
|
if ((settings = switch_xml_child(cfg, "settings"))) {
|
|
|
|
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");
|
|
|
|
|
|
|
|
if (!strcasecmp(var, "colorize") && switch_true(val)) {
|
2007-03-04 22:19:39 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
2007-03-30 00:13:31 +00:00
|
|
|
if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
|
2007-03-04 22:19:39 +00:00
|
|
|
wOldColorAttrs = csbiInfo.wAttributes;
|
|
|
|
COLORIZE = 1;
|
|
|
|
}
|
|
|
|
#else
|
2007-02-28 18:28:07 +00:00
|
|
|
COLORIZE = 1;
|
2007-03-04 22:19:39 +00:00
|
|
|
#endif
|
2009-10-23 16:03:42 +00:00
|
|
|
} else if (!strcasecmp(var, "loglevel") && !zstr(val)) {
|
2008-02-04 18:22:29 +00:00
|
|
|
hard_log_level = switch_log_str2level(val);
|
|
|
|
}
|
2007-02-28 18:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-10 03:23:05 +00:00
|
|
|
switch_xml_free(xml);
|
|
|
|
|
2006-04-12 17:51:47 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-05-27 04:54:52 +00:00
|
|
|
static int can_write(FILE * handle, int ms)
|
2008-01-25 23:09:33 +00:00
|
|
|
{
|
|
|
|
#ifndef WIN32
|
|
|
|
int aok = 1;
|
|
|
|
fd_set can_write;
|
|
|
|
int fd;
|
|
|
|
struct timeval to;
|
|
|
|
int sec, usec;
|
|
|
|
|
|
|
|
sec = ms / 1000;
|
|
|
|
usec = ms % 1000;
|
|
|
|
|
|
|
|
fd = fileno(handle);
|
|
|
|
memset(&to, 0, sizeof(to));
|
2009-04-22 23:42:11 +00:00
|
|
|
FD_ZERO(&can_write);
|
2008-01-25 23:09:33 +00:00
|
|
|
FD_SET(fd, &can_write);
|
|
|
|
to.tv_sec = sec;
|
|
|
|
to.tv_usec = usec;
|
2008-05-27 04:54:52 +00:00
|
|
|
if (select(fd + 1, NULL, &can_write, NULL, &to) > 0) {
|
2008-01-25 23:09:33 +00:00
|
|
|
aok = FD_ISSET(fd, &can_write);
|
|
|
|
} else {
|
|
|
|
aok = 0;
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-01-25 23:09:33 +00:00
|
|
|
return aok;
|
2008-05-27 04:54:52 +00:00
|
|
|
#else
|
2008-01-25 23:09:33 +00:00
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t switch_console_logger(const switch_log_node_t *node, switch_log_level_t level)
|
2006-04-11 21:13:44 +00:00
|
|
|
{
|
|
|
|
FILE *handle;
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
if (!RUNNING) {
|
2007-12-05 20:24:20 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-09-29 01:06:08 +00:00
|
|
|
}
|
2008-02-20 03:56:38 +00:00
|
|
|
#if 0
|
2008-01-25 23:09:33 +00:00
|
|
|
if (failed_write) {
|
|
|
|
if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) {
|
2008-02-20 00:30:39 +00:00
|
|
|
int aok = can_write(handle, 100);
|
2008-01-25 23:09:33 +00:00
|
|
|
if (aok) {
|
|
|
|
const char *msg = "Failed to write to the console! Logging disabled! RE-enable with the 'console loglevel' command\n";
|
2008-01-26 04:07:48 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s", msg);
|
|
|
|
#else
|
2008-01-25 23:09:33 +00:00
|
|
|
if (COLORIZE) {
|
2008-05-27 04:54:52 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s%s%s", COLORS[1], msg, SWITCH_SEQ_DEFAULT_COLOR);
|
2008-01-25 23:09:33 +00:00
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s", msg);
|
|
|
|
}
|
2008-01-26 04:07:48 +00:00
|
|
|
#endif
|
2008-01-25 23:09:33 +00:00
|
|
|
failed_write = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 03:56:38 +00:00
|
|
|
#endif
|
2008-01-25 23:09:33 +00:00
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
if (level > hard_log_level) {
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) {
|
2008-05-27 04:54:52 +00:00
|
|
|
size_t mask = 0;
|
|
|
|
size_t ok = 0;
|
|
|
|
|
|
|
|
ok = switch_log_check_mask(all_level, level);
|
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
if (log_hash) {
|
|
|
|
if (!ok) {
|
|
|
|
mask = (size_t) switch_core_hash_find(log_hash, node->file);
|
|
|
|
ok = switch_log_check_mask(mask, level);
|
2006-04-12 17:51:47 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
if (!ok) {
|
|
|
|
mask = (size_t) switch_core_hash_find(log_hash, node->func);
|
|
|
|
ok = switch_log_check_mask(mask, level);
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
2006-04-14 15:59:22 +00:00
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
if (ok) {
|
2008-01-25 23:09:33 +00:00
|
|
|
#ifndef WIN32
|
2008-02-20 00:30:39 +00:00
|
|
|
int aok = can_write(handle, 10000);
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-01-25 23:09:33 +00:00
|
|
|
if (!aok) {
|
2008-02-20 20:15:45 +00:00
|
|
|
//hard_log_level = 0;
|
|
|
|
//failed_write++;
|
2008-01-25 23:09:33 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-28 18:28:07 +00:00
|
|
|
if (COLORIZE) {
|
2007-03-04 22:19:39 +00:00
|
|
|
#ifdef WIN32
|
2008-10-10 18:33:20 +00:00
|
|
|
DWORD len = (DWORD) strlen(node->data);
|
|
|
|
DWORD outbytes = 0;
|
2007-03-04 22:19:39 +00:00
|
|
|
SetConsoleTextAttribute(hStdout, COLORS[node->level]);
|
2008-10-10 18:33:20 +00:00
|
|
|
WriteFile(hStdout, node->data, len, &outbytes, NULL);
|
2007-03-04 22:19:39 +00:00
|
|
|
SetConsoleTextAttribute(hStdout, wOldColorAttrs);
|
|
|
|
#else
|
2007-02-28 18:28:07 +00:00
|
|
|
fprintf(handle, "%s%s%s", COLORS[node->level], node->data, SWITCH_SEQ_DEFAULT_COLOR);
|
2007-03-04 22:19:39 +00:00
|
|
|
#endif
|
2007-02-28 18:28:07 +00:00
|
|
|
} else {
|
|
|
|
fprintf(handle, "%s", node->data);
|
|
|
|
}
|
2006-04-12 17:51:47 +00:00
|
|
|
}
|
2006-04-11 21:13:44 +00:00
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-04-11 21:13:44 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
SWITCH_STANDARD_API(console_api_function)
|
|
|
|
{
|
|
|
|
int argc;
|
2009-10-07 01:08:36 +00:00
|
|
|
char *mycmd = NULL, *argv[3] = { 0 };
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
const char *usage_string = "USAGE:\n"
|
|
|
|
"--------------------------------------------------------------------------------\n"
|
|
|
|
"console help\n"
|
|
|
|
"console loglevel [[0-7] | <loglevel_string>]\n"
|
2010-02-06 03:38:24 +00:00
|
|
|
"console colorize [on|off|toggle]\n" "--------------------------------------------------------------------------------\n";
|
2009-10-07 01:08:36 +00:00
|
|
|
const char *loglevel_usage_string = "USAGE:\n"
|
|
|
|
"--------------------------------------------------------------------------------\n"
|
|
|
|
"console loglevel [[0-7] | <loglevel_string>]\n"
|
|
|
|
"\n"
|
|
|
|
"Set the logging verbosity of the console from 0 (least verbose) to\n"
|
|
|
|
"7 (debugging), or specify the loglevel as a string:\n"
|
|
|
|
"\n"
|
|
|
|
" 0 console\n"
|
|
|
|
" 1 alert\n"
|
|
|
|
" 2 crit\n"
|
|
|
|
" 3 err\n"
|
2010-02-06 03:38:24 +00:00
|
|
|
" 4 warning\n" " 5 notice\n" " 6 info\n" " 7 debug\n" "--------------------------------------------------------------------------------\n";
|
2009-10-07 01:08:36 +00:00
|
|
|
const char *colorize_usage_string = "USAGE:\n"
|
|
|
|
"--------------------------------------------------------------------------------\n"
|
|
|
|
"console colorize [on|off|toggle]\n"
|
2010-02-06 03:38:24 +00:00
|
|
|
"\n" "Enable, disable, or toggle console coloring.\n" "--------------------------------------------------------------------------------\n";
|
2009-10-07 01:08:36 +00:00
|
|
|
|
|
|
|
if (session)
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(cmd)) {
|
2009-10-07 01:08:36 +00:00
|
|
|
stream->write_function(stream, "%s", usage_string);
|
|
|
|
goto done;
|
2008-05-27 04:54:52 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 01:08:36 +00:00
|
|
|
if (!(mycmd = strdup(cmd))) {
|
|
|
|
status = SWITCH_STATUS_MEMERR;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-12-05 20:24:20 +00:00
|
|
|
|
2009-10-07 01:08:36 +00:00
|
|
|
if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || !argv[0]) {
|
|
|
|
stream->write_function(stream, "%s", usage_string);
|
|
|
|
goto done;
|
|
|
|
}
|
2007-12-05 20:24:20 +00:00
|
|
|
|
2009-10-07 01:08:36 +00:00
|
|
|
if (!strcasecmp(argv[0], "loglevel")) {
|
|
|
|
int level = hard_log_level;
|
2007-12-05 20:24:20 +00:00
|
|
|
|
2009-10-07 01:08:36 +00:00
|
|
|
if (argc > 1) {
|
|
|
|
if (!strcasecmp(argv[1], "help")) {
|
|
|
|
stream->write_function(stream, "%s", loglevel_usage_string);
|
|
|
|
goto done;
|
|
|
|
} else if (*argv[1] > 47 && *argv[1] < 58) {
|
|
|
|
level = atoi(argv[1]);
|
|
|
|
} else {
|
|
|
|
level = switch_log_str2level(argv[1]);
|
2010-02-06 03:38:24 +00:00
|
|
|
}
|
2009-10-07 01:08:36 +00:00
|
|
|
}
|
|
|
|
if (level == SWITCH_LOG_INVALID) {
|
2010-02-06 03:38:24 +00:00
|
|
|
stream->write_function(stream, "-ERR Invalid console loglevel (%s)!\n\n", argc > 1 ? argv[1] : "");
|
2009-10-07 01:08:36 +00:00
|
|
|
} else {
|
|
|
|
hard_log_level = level;
|
|
|
|
stream->write_function(stream, "+OK console log level set to %s\n", switch_log_level2str(hard_log_level));
|
2007-12-05 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 01:08:36 +00:00
|
|
|
} else if (!strcasecmp(argv[0], "colorize")) {
|
|
|
|
if (argc > 1) {
|
|
|
|
if (!strcasecmp(argv[1], "help")) {
|
|
|
|
stream->write_function(stream, "%s", colorize_usage_string);
|
|
|
|
goto done;
|
|
|
|
} else if (!strcasecmp(argv[1], "toggle")) {
|
|
|
|
COLORIZE ^= 1;
|
2007-12-10 19:16:50 +00:00
|
|
|
} else {
|
2008-01-25 23:09:33 +00:00
|
|
|
COLORIZE = switch_true(argv[1]);
|
|
|
|
}
|
2007-12-05 20:24:20 +00:00
|
|
|
}
|
2009-10-07 01:08:36 +00:00
|
|
|
stream->write_function(stream, "+OK console color %s\n", COLORIZE ? "enabled" : "disabled");
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
} else { /* if (!strcasecmp(argv[0], "help")) { */
|
2009-10-07 01:08:36 +00:00
|
|
|
stream->write_function(stream, "%s", usage_string);
|
2007-12-05 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
done:
|
2009-10-07 01:08:36 +00:00
|
|
|
switch_safe_free(mycmd);
|
|
|
|
return status;
|
2007-12-05 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_console_load)
|
2006-04-11 21:13:44 +00:00
|
|
|
{
|
2007-12-05 20:24:20 +00:00
|
|
|
switch_api_interface_t *api_interface;
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2006-04-12 17:51:47 +00:00
|
|
|
|
2007-12-05 20:24:20 +00:00
|
|
|
module_pool = pool;
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2006-04-11 21:13:44 +00:00
|
|
|
/* connect my internal structure to the blank pointer passed to me */
|
2007-06-20 07:53:33 +00:00
|
|
|
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
2006-04-11 21:13:44 +00:00
|
|
|
|
2009-10-07 01:08:36 +00:00
|
|
|
SWITCH_ADD_API(api_interface, "console", "Console", console_api_function, "loglevel [level]|colorize [on|toggle|off]");
|
|
|
|
switch_console_set_complete("add console help");
|
2009-03-05 21:38:32 +00:00
|
|
|
switch_console_set_complete("add console loglevel");
|
2009-10-07 01:08:36 +00:00
|
|
|
switch_console_set_complete("add console loglevel help");
|
|
|
|
switch_console_set_complete("add console loglevel console");
|
|
|
|
switch_console_set_complete("add console loglevel alert");
|
|
|
|
switch_console_set_complete("add console loglevel crit");
|
|
|
|
switch_console_set_complete("add console loglevel err");
|
|
|
|
switch_console_set_complete("add console loglevel warning");
|
|
|
|
switch_console_set_complete("add console loglevel notice");
|
|
|
|
switch_console_set_complete("add console loglevel info");
|
|
|
|
switch_console_set_complete("add console loglevel debug");
|
2009-03-05 21:38:32 +00:00
|
|
|
switch_console_set_complete("add console colorize");
|
2009-10-07 01:08:36 +00:00
|
|
|
switch_console_set_complete("add console colorize help");
|
|
|
|
switch_console_set_complete("add console colorize on");
|
|
|
|
switch_console_set_complete("add console colorize off");
|
|
|
|
switch_console_set_complete("add console colorize toggle");
|
2007-12-05 20:24:20 +00:00
|
|
|
|
2006-04-11 21:13:44 +00:00
|
|
|
/* setup my logger function */
|
2008-07-11 14:35:08 +00:00
|
|
|
switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG, SWITCH_TRUE);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-04-12 17:51:47 +00:00
|
|
|
config_logger();
|
2007-09-29 01:06:08 +00:00
|
|
|
RUNNING = 1;
|
2006-04-11 21:13:44 +00:00
|
|
|
/* indicate that the module should continue to be loaded */
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_console_shutdown)
|
|
|
|
{
|
2008-07-11 14:35:08 +00:00
|
|
|
|
|
|
|
switch_log_unbind_logger(switch_console_logger);
|
2008-09-11 19:56:57 +00:00
|
|
|
if (log_hash) {
|
|
|
|
switch_core_hash_destroy(&log_hash);
|
|
|
|
}
|
2008-07-11 14:35:08 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
RUNNING = 0;
|
2008-07-11 14:35:08 +00:00
|
|
|
return SWITCH_STATUS_UNLOAD;
|
2007-09-29 01:06:08 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 22:30:48 +00:00
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2006-11-27 22:30:48 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2008-07-03 19:12:26 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
2006-11-27 22:30:48 +00:00
|
|
|
*/
|