[Freeswitch-branches] [commit] r5027 - freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file
Freeswitch SVN
anthonyl at freeswitch.org
Fri Apr 27 12:32:16 EDT 2007
Author: anthonyl
Date: Fri Apr 27 12:32:15 2007
New Revision: 5027
Modified:
freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c
Log:
brushing the dust off this guy, and getting it ready to fly.
Modified: freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c
==============================================================================
--- freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c (original)
+++ freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c Fri Apr 27 12:32:15 2007
@@ -34,9 +34,10 @@
#include <syslog.h>
#define MAX_LENGTH 1024
-#define DEFAULT_FORMAT "${data}" /* for the most part this contains all that we need by default */
+#define DEFAULT_FORMAT "${data}"
#define DEFAULT_LOGFILE "/var/log/freeswitch"
#define DEFAULT_LIMIT 0x7FFFFFFF
+#define WARM_FUZZY_OFFSET 64
static const uint8_t STATIC_LEVELS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
static const char modname[] = "mod_log2file";
@@ -85,11 +86,46 @@
static switch_status_t mod_log2file_rotate(void)
{
int fd;
- int fd2;
+ int ret;
+ unsigned int i;
unsigned char *p;
+ unsigned char *q;
globals.log_size = 0;
+
+ ret = fseek(globals.log_fd, 0, SEEK_SET);
+
+ if (ret < 0) {
+ return SWITCH_STATUS_FALSE;
+ }
+ p = malloc(strlen(globals.logfile)+WARM_FUZZY_OFFSET);
+ if (!p) {
+ return SWITCH_STATUS_FALSE;
+ }
+ q = malloc(1024);
+ if (!q) {
+ free(p);
+ return SWITCH_STATUS_FALSE;
+ }
+ memset(p, '\0', strlen(globals.logfile)+WARM_FUZZY_OFFSET);
+ for (i=1;i<MAX_UINT; i++) {
+ sprintf(p, "%s.%i", globals.logfile, i);
+ fd = fopen(p, 'w+');
+ if (fd)
+ break;
+ }
+ do {
+ memset(q, '\0', 1024);
+ ret = fread(q, 1024, 1, globals.log_fd);
+ fwrite(q, 1024, 1, fd);
+ globals.log_size = off;
+ } while(ret);
+
+ ret = fseek(globals.log_fd, 0, SEEK_SET);
+
+ free(p);
+ free(q);
return SWITCH_STATUS_SUCCESS;
}
@@ -101,14 +137,11 @@
if((off = ftello(globals.log_fd)) < 0) {
return SWITCH_STATUS_FALSE;
}
-
- printf("\n****** OFF is %i\n", off);
if (off >= DEFAULT_LIMIT) {
return mod_log2file_rotate();
}
- globals.log_size = off;
return SWITCH_STATUS_SUCCESS;
}
@@ -140,18 +173,24 @@
char *message = NULL;
char line_no[sizeof(int)*8+1];
char date[80] = "";
+ uint8_t *lookup = NULL;
+ switch_log_level_t level = SWITCH_LOG_DEBUG;
switch_time_exp_t time;
switch_size_t retsize;
-
+
message = (char *)malloc(strlen(globals.format)+2);
+ if (!message) {
+ return SWITCH_STATUS_FALSE;
+ }
switch_copy_string(message, globals.format, strlen(globals.format)+1);
-
+
message = switch_string_replace(message, "${data}", node->data);
message = switch_string_replace(message, "${message}", node->content);
if (switch_time_exp_lt(&time, node->timestamp) != SWITCH_STATUS_SUCCESS) {
- return SWITCH_STATUS_FALSE;
+ free(message);
+ return SWITCH_STATUS_FALSE;
}
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &time);
@@ -184,13 +223,12 @@
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 (!strcmp(var, "logfile")) {
set_global_logfile(val);
} else if (!strcmp(var, "format")) {
- set_global_format(val);;
- }
-
+ set_global_format(val);
+ }
+
}
}
switch_xml_free(xml);
@@ -218,14 +256,13 @@
mod_log2file_openlogfile();
switch_log_bind_logger(mod_log2file_logger, SWITCH_LOG_DEBUG);
-
- return SWITCH_STATUS_SUCCESS;
+
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_unload(const switch_loadable_module_interface_t **interface)
{
- closelog();
-
+ closelog();
return SWITCH_STATUS_SUCCESS;
}
More information about the Freeswitch-branches
mailing list