[Freeswitch-svn] [commit] r6068 - freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_syslog
Freeswitch SVN
anthonyl at freeswitch.org
Sat Oct 27 13:01:53 EDT 2007
Author: anthonyl
Date: Sat Oct 27 13:01:53 2007
New Revision: 6068
Modified:
freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_syslog/mod_syslog.c
Log:
more levels managment
Modified: freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_syslog/mod_syslog.c
==============================================================================
--- freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_syslog/mod_syslog.c (original)
+++ freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_syslog/mod_syslog.c Sat Oct 27 13:01:53 2007
@@ -32,23 +32,33 @@
#include <switch.h>
#include <stdlib.h>
#include <syslog.h>
-
#define DEFAULT_IDENT "freeswitch"
#define DEFAULT_FACILITY "user"
#define DEFAULT_LEVEL "warning"
#define DEFAULT_FORMAT "[message]"
#define MAX_LENGTH 1024
-
static const char modname[] = "mod_syslog";
static switch_status_t load_config(void);
-
+struct level_set {
+ int level;
+ int on;
+}static levels[] = {
+ {SWITCH_LOG_EMERG, 0}, /* 0 */
+ {SWITCH_LOG_ALERT, 0}, /* 1 */
+ {SWITCH_LOG_CRIT, 0}, /* 2 */
+ {SWITCH_LOG_ERROR, 0}, /* 3 */
+ {SWITCH_LOG_WARNING, 0}, /* 4 */
+ {SWITCH_LOG_NOTICE, 0}, /* 5 */
+ {SWITCH_LOG_INFO, 0}, /* 6 */
+ {SWITCH_LOG_DEBUG, 0}, /* 7 */
+ {SWITCH_LOG_CONSOLE, 0}, /* 8 */
+};
static struct {
char *ident;
char *facility;
char *level;
char *format;
} globals;
-
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ident, globals.ident)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_level, globals.level)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_format, globals.format)
@@ -66,7 +76,6 @@
/*.speech_interface */ NULL,
/*.directory_interface */ NULL
};
-
static switch_status_t mod_syslog_logger(const switch_log_node_t *node, switch_log_level_t level)
{
char *message = NULL;
@@ -74,17 +83,15 @@
char date[80] = "";
switch_time_exp_t time;
switch_size_t retsize;
-
+ if (!levels[node->level].on) {
+ return SWITCH_STATUS_SUCCESS;
+ }
message = (char *) malloc(strlen(globals.format) + 2);
-
switch_copy_string(message, globals.format, strlen(globals.format) + 1);
-
message = switch_string_replace(message, "${message}", node->content);
-
if (switch_time_exp_lt(&time, node->timestamp) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
-
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &time);
message = switch_string_replace(message, "${time}", date);
@@ -97,12 +104,44 @@
if (!switch_strlen_zero(message)) {
syslog(LOG_ERR, "%s", message);
}
-
free(message);
-
return SWITCH_STATUS_SUCCESS;
}
-
+static void process_levels(char *p)
+{
+ char *q;
+ if (!p) /* be safe like a trojan! */
+ return;
+ while ((q = strsep(&p, ","))) {
+ if (!strncasecmp(q, "emerg", strlen(q))) {
+ levels[SWITCH_LOG_EMERG].on = 1;
+ } else if (!strncasecmp(q, "alert", strlen(q))) {
+ levels[SWITCH_LOG_ALERT].on = 1;
+ } else if (!strncasecmp(q, "crit", strlen(q))) {
+ levels[SWITCH_LOG_CRIT].on = 1;
+ } else if (!strncasecmp(q, "error", strlen(q))) {
+ levels[SWITCH_LOG_ERROR].on = 1;
+ } else if (!strncasecmp(q, "warn", strlen(q))) {
+ levels[SWITCH_LOG_WARNING].on = 1;
+ } else if (!strncasecmp(q, "notice", strlen(q))) {
+ levels[SWITCH_LOG_NOTICE].on = 1;
+ } else if (!strncasecmp(q, "info", strlen(q))) {
+ levels[SWITCH_LOG_INFO].on = 1;
+ } else if (!strncasecmp(q, "debug", strlen(q))) {
+ levels[SWITCH_LOG_DEBUG].on = 1;
+ } else if (!strncasecmp(q, "console", strlen(q))) {
+ levels[SWITCH_LOG_CONSOLE].on = 1;
+ } else if (!strncasecmp(q, "all", strlen(q))) {
+ int i;
+ printf("all option!\n");
+ for (i=0; i < (sizeof(levels) / sizeof(struct level_set)); i++) {
+ levels[i].on = 1;
+ }
+ }
+
+ }
+ return;
+}
static switch_status_t load_config(void)
{
char *cf = "syslog.conf";
More information about the Freeswitch-svn
mailing list