00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "log4c.h"
00028 #include <stdio.h>
00029
00030
00031
00032
00033
00034 static char *priorityNames[] = {
00035 "Zero Priority",
00036 "TRACE",
00037 "DEBUG",
00038 "INFO",
00039 "NOTICE",
00040 "WARNING",
00041 "ERROR",
00042 "CRITICAL ERROR",
00043 "ALERT",
00044 "EMERGENCY",
00045 };
00046
00047 static void doAppend(struct LogAppender* this, struct LogEvent* ev);
00048
00049 static struct DefaultLogAppender {
00050 struct LogAppender appender;
00051 FILE *file;
00052 int printLoc;
00053 } defaultLogAppender = { { doAppend }, NULL, 1 } ;
00054
00055 struct LogAppender* log_defaultLogAppender = &defaultLogAppender.appender;
00056
00057 static void doAppend(struct LogAppender* this0, struct LogEvent* ev) {
00058
00059
00060 char *pn = NULL;
00061 char buf[20];
00062 struct DefaultLogAppender* this = (struct DefaultLogAppender*)this0;
00063
00064 if (this->file == NULL) this->file = stderr;
00065
00066 if (ev->priority < 0) {
00067 pn = "???";
00068 }
00069 else if ((size_t)ev->priority < sizeof(priorityNames)) {
00070 pn = priorityNames[ev->priority];
00071 } else {
00072 sprintf(buf, "%s+%d",
00073 priorityNames[sizeof(priorityNames)-1],
00074 ev->priority - (int) sizeof(priorityNames) + 1);
00075 }
00076 fprintf(this->file, "%-7s ", pn);
00077 if (this->printLoc)
00078 fprintf(this->file, "%s:%d:%s\t",
00079 ev->fileName, ev->lineNum, ev->functionName);
00080 else
00081 fprintf(this->file, "%s: ",
00082 ev->cat->name);
00083 vfprintf(this->file, ev->fmt, ev->ap);
00084 fprintf(this->file, "\n");
00085 }