[Freeswitch-svn] [commit] r10893 - in freeswitch/trunk: libs/esl libs/esl/src src src/include src/mod/event_handlers/mod_event_socket
FreeSWITCH SVN
anthm at freeswitch.org
Sat Dec 20 06:56:10 PST 2008
Author: anthm
Date: Sat Dec 20 09:56:08 2008
New Revision: 10893
Log:
change event_socket to have more info about log lines
Modified:
freeswitch/trunk/libs/esl/fs_cli.c
freeswitch/trunk/libs/esl/src/esl.c
freeswitch/trunk/src/include/switch_log.h
freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
freeswitch/trunk/src/switch_log.c
Modified: freeswitch/trunk/libs/esl/fs_cli.c
==============================================================================
--- freeswitch/trunk/libs/esl/fs_cli.c (original)
+++ freeswitch/trunk/libs/esl/fs_cli.c Sat Dec 20 09:56:08 2008
@@ -71,30 +71,34 @@
if (handle->last_event) {
const char *type = esl_event_get_header(handle->last_event, "content-type");
- if (!strcasecmp(type, "log/data")) {
- int level = 0;
- if (strstr(handle->last_event->body, "[CONSOLE]")) {
- level = 0;
- } else if (strstr(handle->last_event->body, "[ALERT]")) {
- level = 1;
- } else if (strstr(handle->last_event->body, "[CRIT]")) {
- level = 2;
- } else if (strstr(handle->last_event->body, "[ERROR]")) {
- level = 3;
- } else if (strstr(handle->last_event->body, "[WARNING]")) {
- level = 4;
- } else if (strstr(handle->last_event->body, "[NOTICE]")) {
- level = 5;
- } else if (strstr(handle->last_event->body, "[INFO]")) {
- level = 6;
- } else if (strstr(handle->last_event->body, "[DEBUG]")) {
- level = 7;
- }
+ int known = 0;
- printf("%s%s%s", COLORS[level], handle->last_event->body, ESL_SEQ_DEFAULT_COLOR);
- } else if (0 && !strcasecmp(type, "text/disconnect-notice")) {
- running = thread_running = 0;
- } else {
+ if (!esl_strlen_zero(type)) {
+ if (!strcasecmp(type, "log/data")) {
+ int level = 0, tchannel = 0;
+ const char *lname = esl_event_get_header(handle->last_event, "log-level");
+ const char *channel = esl_event_get_header(handle->last_event, "text-channel");
+ const char *file = esl_event_get_header(handle->last_event, "log-file");
+
+ if (channel) {
+ tchannel = atoi(channel);
+ }
+
+ if (lname) {
+ level = atoi(lname);
+ }
+
+ if (tchannel == 0 || (file && !strcmp(file, "switch_console.c"))) {
+ printf("%s%s%s", COLORS[level], handle->last_event->body, ESL_SEQ_DEFAULT_COLOR);
+ }
+ known++;
+ } else if (!strcasecmp(type, "text/disconnect-notice")) {
+ running = thread_running = 0;
+ known++;
+ }
+ }
+
+ if (!known) {
printf("INCOMING DATA [%s]\n%s", type, handle->last_event->body);
}
}
@@ -108,6 +112,7 @@
done:
thread_running = 0;
+ esl_log(ESL_LOG_DEBUG, "Thread Done\n");
return NULL;
}
@@ -181,7 +186,7 @@
signal(SIGINT, handle_SIGINT);
gethostname(hostname, sizeof(hostname));
- handle.debug = 0;
+ handle.debug = 1;
if (esl_config_open_file(&cfg, cfile)) {
Modified: freeswitch/trunk/libs/esl/src/esl.c
==============================================================================
--- freeswitch/trunk/libs/esl/src/esl.c (original)
+++ freeswitch/trunk/libs/esl/src/esl.c Sat Dec 20 09:56:08 2008
@@ -446,7 +446,6 @@
rrval = recv(handle->sock, c, 1, 0);
if (rrval == 0) {
-
if (++zc >= 100) {
esl_disconnect(handle);
return ESL_FAIL;
@@ -588,6 +587,27 @@
free(body);
+ if ((cl = esl_event_get_header(handle->last_ievent, "content-length"))) {
+ esl_ssize_t sofar = 0;
+
+ len = atol(cl);
+ body = malloc(len+1);
+ esl_assert(body);
+ *(body + len) = '\0';
+
+ do {
+ esl_ssize_t r;
+ if ((r = recv(handle->sock, body + sofar, len - sofar, 0)) < 0) {
+ strerror_r(handle->errno, handle->err, sizeof(handle->err));
+ goto fail;
+ }
+ sofar += r;
+ } while (sofar < len);
+
+ handle->last_ievent->body = body;
+ }
+
+
if (handle->debug) {
char *foo;
esl_event_serialize(handle->last_ievent, &foo, ESL_FALSE);
Modified: freeswitch/trunk/src/include/switch_log.h
==============================================================================
--- freeswitch/trunk/src/include/switch_log.h (original)
+++ freeswitch/trunk/src/include/switch_log.h Sat Dec 20 09:56:08 2008
@@ -63,7 +63,7 @@
char *content;
const char *userdata;
/* To maintain abi, only add new elements to the end of this struct and do not delete any elements */
-
+ switch_text_channel_t channel;
} switch_log_node_t;
typedef switch_status_t (*switch_log_function_t) (const switch_log_node_t *node, switch_log_level_t level);
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Sat Dec 20 09:56:08 2008
@@ -134,29 +134,32 @@
static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
{
listener_t *l;
-
+
switch_mutex_lock(globals.listener_mutex);
for (l = listen_list.listeners; l; l = l->next) {
if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
- char *data = strdup(node->data);
- if (data) {
- if (switch_queue_trypush(l->log_queue, data) == SWITCH_STATUS_SUCCESS) {
- if (l->lost_logs) {
- int ll = l->lost_logs;
- switch_event_t *event;
- l->lost_logs = 0;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Lost %d log lines!\n", ll);
- if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "info", "lost %d log lines", ll);
- switch_event_fire(&event);
- }
+ switch_log_node_t *dnode = malloc(sizeof(*node));
+
+ switch_assert(dnode);
+ *dnode = *node;
+ dnode->data = strdup(node->data);
+ switch_assert(dnode->data);
+
+ if (switch_queue_trypush(l->log_queue, dnode) == SWITCH_STATUS_SUCCESS) {
+ if (l->lost_logs) {
+ int ll = l->lost_logs;
+ switch_event_t *event;
+ l->lost_logs = 0;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Lost %d log lines!\n", ll);
+ if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "info", "lost %d log lines", ll);
+ switch_event_fire(&event);
}
- } else {
- switch_safe_free(data);
- l->lost_logs++;
}
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
+ switch_safe_free(dnode->data);
+ switch_safe_free(dnode);
+ l->lost_logs++;
}
}
}
@@ -171,7 +174,11 @@
if (listener->log_queue) {
while (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
- if (pop) free(pop);
+ switch_log_node_t *dnode = (switch_log_node_t *) pop;
+ if (dnode) {
+ free(dnode->data);
+ free(dnode);
+ }
}
}
@@ -981,17 +988,32 @@
if (!*mbuf) {
if (switch_test_flag(listener, LFLAG_LOG)) {
if (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
- char *data = (char *) pop;
-
-
- if (data) {
- switch_snprintf(buf, sizeof(buf), "Content-Type: log/data\nContent-Length: %" SWITCH_SSIZE_T_FMT "\n\n", strlen(data));
+ switch_log_node_t *dnode = (switch_log_node_t *) pop;
+
+ if (dnode->data) {
+ switch_snprintf(buf, sizeof(buf),
+ "Content-Type: log/data\n"
+ "Content-Length: %" SWITCH_SSIZE_T_FMT "\n"
+ "Log-Level: %d\n"
+ "Text-Channel: %d\n"
+ "Log-File: %s\n"
+ "Log-Func: %s\n"
+ "Log->Line: %d\n"
+ "\n",
+ strlen(dnode->data),
+ dnode->level,
+ dnode->channel,
+ dnode->file,
+ dnode->func,
+ dnode->line
+ );
len = strlen(buf);
switch_socket_send(listener->sock, buf, &len);
- len = strlen(data);
- switch_socket_send(listener->sock, data, &len);
+ len = strlen(dnode->data);
+ switch_socket_send(listener->sock, dnode->data, &len);
- free(data);
+ free(dnode->data);
+ free(dnode);
}
do_sleep = 0;
}
Modified: freeswitch/trunk/src/switch_log.c
==============================================================================
--- freeswitch/trunk/src/switch_log.c (original)
+++ freeswitch/trunk/src/switch_log.c Sat Dec 20 09:56:08 2008
@@ -352,7 +352,7 @@
node = malloc(sizeof(*node));
switch_assert(node);
}
-
+
node->data = data;
data = NULL;
switch_set_string(node->file, filep);
@@ -361,7 +361,7 @@
node->level = level;
node->content = content;
node->timestamp = now;
-
+ node->channel = channel;
if (switch_queue_trypush(LOG_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
free(node->data);
More information about the Freeswitch-svn
mailing list