[asterisk-dev] Re: custom-cdr output to syslog hack

Michael Iedema michael at askozia.com
Wed Apr 18 01:33:37 MST 2007


> I'm working on an embedded project where all logging facilities must
> be circularized (fixed size logs, not log rotation) to keep my ram
> disk from getting eaten up.  I already have a clogged syslog
> implementation and, instead of reinventing the wheel writing a clogged
> cdr handler, I'm hacking cdr output to syslog.

I could have figured that this topic would inspire such energetic discussion. ;)

In case someone finds themselves in the same situation, I'm posting my
patch for the archive and public ridicule.

--Michael I.



diff -ur asterisk-1.4.2-orig/cdr/cdr_custom.c asterisk-1.4.2/cdr/cdr_custom.c
--- asterisk-1.4.2-orig/cdr/cdr_custom.c	2006-10-25 16:32:08.000000000 +0200
+++ asterisk-1.4.2/cdr/cdr_custom.c	2007-04-17 16:20:01.000000000 +0200
@@ -122,16 +122,17 @@
 	/* because of the absolutely unconditional need for the
 	   highest reliability possible in writing billing records,
 	   we open write and close the log file each time */
-	mf = fopen(master, "a");
+	/*mf = fopen(master, "a");
  	if (!mf) {
  		ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n",
master, strerror(errno));
 	}
  	if (mf) {
  		fputs(buf, mf);
-		fflush(mf); /* be particularly anal here */
-		fclose(mf);
+		fflush(mf); *//* be particularly anal here */
+		/*fclose(mf);
  		mf = NULL;
-	}
+	}*/
+	ast_log(LOG_CDR, "%s", buf);
 	return 0;
 }


diff -ur asterisk-1.4.2-orig/include/asterisk/logger.h
asterisk-1.4.2/include/asterisk/logger.h
--- asterisk-1.4.2-orig/include/asterisk/logger.h	2006-09-28
20:05:43.000000000 +0200
+++ asterisk-1.4.2/include/asterisk/logger.h	2007-04-17 16:04:22.000000000 +0200
@@ -129,6 +129,12 @@
 #define __LOG_DTMF  6
 #define LOG_DTMF    __LOG_DTMF, _A_

+#ifdef LOG_CDR
+#undef LOG_CDR
+#endif
+#define __LOG_CDR  7
+#define LOG_CDR    __LOG_CDR, _A_
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
  #endif
diff -ur asterisk-1.4.2-orig/main/logger.c asterisk-1.4.2/main/logger.c
--- asterisk-1.4.2-orig/main/logger.c	2006-12-27 23:06:56.000000000 +0100
+++ asterisk-1.4.2/main/logger.c	2007-04-17 16:27:03.000000000 +0200
@@ -54,7 +54,8 @@
 	LOG_WARNING,
 	LOG_ERR,
 	LOG_DEBUG,
-	LOG_DEBUG
+	LOG_DEBUG,
+	LOG_INFO
 };

  #define SYSLOG_NLEVELS sizeof(syslog_level_map) / sizeof(int)
@@ -121,7 +122,8 @@
 	"WARNING",
 	"ERROR",
 	"VERBOSE",
-	"DTMF"
+	"DTMF",
+	"CDR"
 };

 static int colors[] = {
@@ -162,6 +164,8 @@
 			res |= (1 << __LOG_VERBOSE);
 		else if (!strcasecmp(w, "dtmf"))
 			res |= (1 << __LOG_DTMF);
+		else if (!strcasecmp(w, "cdr"))
+			res |= (1 << __LOG_CDR);
 		else {
 			fprintf(stderr, "Logfile Warning: Unknown keyword '%s' at line %d
of logger.conf\n", w, lineno);
 		}
@@ -663,6 +667,9 @@
 	} else if (level == __LOG_DTMF) {
  		snprintf(buf, sizeof(buf), "DTMF[%ld]: ", (long)GETTID());
 		level = __LOG_DEBUG;
+	} else if (level == __LOG_CDR) {
+		snprintf(buf, sizeof(buf), "CDR[%ld]: ", (long)GETTID());
+		level = __LOG_CDR;
 	} else {
  		snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: ",
 			 levels[level], (long)GETTID(), file, line, function);


More information about the asterisk-dev mailing list