#include "common.h"#include "log.h"#include "errabort.h"#include "dystring.h"#include "options.h"#include "portable.h"#include <syslog.h>#include <time.h>Include dependency graph for log.c:

Go to the source code of this file.
Functions | |
| static void | logWarnHander (char *format, va_list args) |
| static void | logAbortHandler () |
| static void | setProgram (char *program) |
| static int | parseFacility (char *facility) |
| void | logOpenSyslog (char *program, char *facility) |
| void | logOpenFile (char *program, char *logFile) |
| FILE * | logGetFile () |
| static void | logFilePrint (char *level, char *format, va_list args) |
| void | logErrorVa (char *format, va_list args) |
| void | logError (char *format,...) |
| void | logWarnVa (char *format, va_list args) |
| void | logWarn (char *format,...) |
| void | logInfoVa (char *format, va_list args) |
| void | logInfo (char *format,...) |
| void | logDebugVa (char *format, va_list args) |
| void | logDebug (char *format,...) |
| void | logDaemonize (char *progName) |
Variables | |
| static char * | gProgram = "unknown" |
| static boolean | gSysLogOn = FALSE |
| static FILE * | gLogFh = NULL |
| struct { | |
| char * name | |
| int fac | |
| } | facilityNameTbl [] |
| static void logAbortHandler | ( | ) | [static] |
Definition at line 65 of file log.c.
References gProgram, and logError().
Referenced by logOpenFile(), and logOpenSyslog().
00067 { 00068 logError("%s aborted", gProgram); 00069 fprintf(stderr, "aborted"); 00070 exit(1); 00071 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logDaemonize | ( | char * | progName | ) |
Definition at line 244 of file log.c.
References logOpenFile(), logOpenSyslog(), mustFork(), optionExists(), and optionVal().
00248 { 00249 if (!optionExists("debug")) 00250 { 00251 int i, maxFiles = getdtablesize(); 00252 if (mustFork() != 0) 00253 exit(0); /* parent goes away */ 00254 00255 /* Close all open files first (before logging) */ 00256 for (i = 0; i < maxFiles; i++) 00257 close(i); 00258 } 00259 00260 /* Set up log handler. */ 00261 if (optionExists("log")) 00262 logOpenFile(progName, optionVal("log", NULL)); 00263 else 00264 logOpenSyslog(progName, optionVal("logFacility", NULL)); 00265 }
Here is the call graph for this function:

| void logDebug | ( | char * | format, | |
| ... | ||||
| ) |
Definition at line 235 of file log.c.
References logDebugVa().
Referenced by dnaQuery(), pcrQuery(), startServer(), transQuery(), and transTransQuery().
00237 { 00238 va_list args; 00239 va_start(args, format); 00240 logDebugVa(format, args); 00241 va_end(args); 00242 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logDebugVa | ( | char * | format, | |
| va_list | args | |||
| ) |
Definition at line 224 of file log.c.
References gLogFh, gSysLogOn, and logFilePrint().
Referenced by logDebug().
00226 { 00227 #ifndef NO_SYSLOG 00228 if (gSysLogOn) 00229 vsyslog(LOG_DEBUG, format, args); 00230 #endif 00231 if (gLogFh != NULL) 00232 logFilePrint("debug", format, args); 00233 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logError | ( | char * | format, | |
| ... | ||||
| ) |
Definition at line 175 of file log.c.
References logErrorVa().
Referenced by errorSafeCleanupMess(), logAbortHandler(), and startServer().
00177 { 00178 va_list args; 00179 va_start(args, format); 00180 logErrorVa(format, args); 00181 va_end(args); 00182 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logErrorVa | ( | char * | format, | |
| va_list | args | |||
| ) |
Definition at line 164 of file log.c.
References gLogFh, gSysLogOn, and logFilePrint().
Referenced by logError(), and logWarnHander().
00166 { 00167 #ifndef NO_SYSLOG 00168 if (gSysLogOn) 00169 vsyslog(LOG_ERR, format, args); 00170 #endif 00171 if (gLogFh != NULL) 00172 logFilePrint("error", format, args); 00173 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void logFilePrint | ( | char * | level, | |
| char * | format, | |||
| va_list | args | |||
| ) | [static] |
Definition at line 151 of file log.c.
References gLogFh.
Referenced by logDebugVa(), logErrorVa(), logInfoVa(), and logWarnVa().
00153 { 00154 static char *timeFmt = "%Y/%m/%d %H:%M:%S"; 00155 char timeBuf[128]; 00156 time_t curTime = time(NULL); 00157 strftime(timeBuf, sizeof(timeBuf), timeFmt, localtime(&curTime)); 00158 fprintf(gLogFh, "%s: %s: ", timeBuf, level); 00159 vfprintf(gLogFh, format, args); 00160 fputc('\n', gLogFh); 00161 fflush(gLogFh); 00162 }
Here is the caller graph for this function:

| FILE* logGetFile | ( | ) |
Definition at line 143 of file log.c.
References gLogFh.
Referenced by startServer().
00147 { 00148 return gLogFh; 00149 }
Here is the caller graph for this function:

| void logInfo | ( | char * | format, | |
| ... | ||||
| ) |
Definition at line 215 of file log.c.
References logInfoVa().
Referenced by startServer().
00217 { 00218 va_list args; 00219 va_start(args, format); 00220 logInfoVa(format, args); 00221 va_end(args); 00222 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logInfoVa | ( | char * | format, | |
| va_list | args | |||
| ) |
Definition at line 204 of file log.c.
References gLogFh, gSysLogOn, and logFilePrint().
Referenced by logInfo().
00206 { 00207 #ifndef NO_SYSLOG 00208 if (gSysLogOn) 00209 vsyslog(LOG_INFO, format, args); 00210 #endif 00211 if (gLogFh != NULL) 00212 logFilePrint("info", format, args); 00213 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logOpenFile | ( | char * | program, | |
| char * | logFile | |||
| ) |
Definition at line 131 of file log.c.
References gLogFh, logAbortHandler(), logWarnHander(), mustOpen(), pushAbortHandler(), pushWarnHandler(), and setProgram().
Referenced by logDaemonize(), and main().
00136 { 00137 setProgram(program); 00138 gLogFh = mustOpen(logFile, "a"); 00139 pushWarnHandler(logWarnHander); 00140 pushAbortHandler(logAbortHandler); 00141 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logOpenSyslog | ( | char * | program, | |
| char * | facility | |||
| ) |
Definition at line 113 of file log.c.
References errAbort(), gSysLogOn, logAbortHandler(), logWarnHander(), parseFacility(), pushAbortHandler(), pushWarnHandler(), setProgram(), and TRUE.
Referenced by logDaemonize(), and main().
00119 { 00120 #ifndef NO_SYSLOG 00121 setProgram(program); 00122 openlog(program, LOG_PID, parseFacility(facility)); 00123 pushWarnHandler(logWarnHander); 00124 pushAbortHandler(logAbortHandler); 00125 gSysLogOn = TRUE; 00126 #else 00127 errAbort("syslog support was not compiled into %s", __FILE__); 00128 #endif 00129 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logWarn | ( | char * | format, | |
| ... | ||||
| ) |
Definition at line 195 of file log.c.
References logWarnVa().
00197 { 00198 va_list args; 00199 va_start(args, format); 00200 logWarnVa(format, args); 00201 va_end(args); 00202 }
Here is the call graph for this function:

| static void logWarnHander | ( | char * | format, | |
| va_list | args | |||
| ) | [static] |
Definition at line 58 of file log.c.
References logErrorVa().
Referenced by logOpenFile(), and logOpenSyslog().
00060 { 00061 /* use logError, since errAbort and warn all print through warn handler */ 00062 logErrorVa(format, args); 00063 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void logWarnVa | ( | char * | format, | |
| va_list | args | |||
| ) |
Definition at line 184 of file log.c.
References gLogFh, gSysLogOn, and logFilePrint().
Referenced by logWarn().
00186 { 00187 #ifndef NO_SYSLOG 00188 if (gSysLogOn) 00189 vsyslog(LOG_WARNING, format, args); 00190 #endif 00191 if (gLogFh != NULL) 00192 logFilePrint("warn", format, args); 00193 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int parseFacility | ( | char * | facility | ) | [static] |
Definition at line 87 of file log.c.
References dyStringAppend(), dyStringNew, errAbort(), fac, facilityNameTbl, name, sameString, and dyString::string.
Referenced by logOpenSyslog().
00089 { 00090 int i; 00091 struct dyString *msg; 00092 if (facility == NULL) 00093 return LOG_LOCAL0; 00094 for (i = 0; facilityNameTbl[i].name != NULL; i++) 00095 { 00096 if (sameString(facilityNameTbl[i].name, facility)) 00097 return facilityNameTbl[i].fac; 00098 } 00099 msg = dyStringNew(256); 00100 00101 for (i = 0; facilityNameTbl[i].name != NULL; i++) 00102 { 00103 if (i > 0) 00104 dyStringAppend(msg, ", "); 00105 dyStringAppend(msg, facilityNameTbl[i].name); 00106 } 00107 00108 errAbort("invalid log facility: %s, expected one of: %s", facility, msg->string); 00109 return 0; /* never reached */ 00110 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void setProgram | ( | char * | program | ) | [static] |
Definition at line 73 of file log.c.
References gProgram, name, needMem(), and splitPath().
Referenced by logOpenFile(), and logOpenSyslog().
00075 { 00076 char name[128], ext[64]; 00077 int len; 00078 splitPath(program, NULL, name, ext); 00079 len = strlen(name) + strlen(ext) + 1; 00080 gProgram = needMem(len); 00081 strcpy(gProgram, name); 00082 if (ext[0] != '\0') 00083 strcat(gProgram, ext); /* includes dot */ 00084 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int fac |
struct { ... } facilityNameTbl[] [static] |
Referenced by parseFacility().
FILE* gLogFh = NULL [static] |
Definition at line 18 of file log.c.
Referenced by logDebugVa(), logErrorVa(), logFilePrint(), logGetFile(), logInfoVa(), logOpenFile(), and logWarnVa().
char* gProgram = "unknown" [static] |
boolean gSysLogOn = FALSE [static] |
Definition at line 17 of file log.c.
Referenced by logDebugVa(), logErrorVa(), logInfoVa(), logOpenSyslog(), and logWarnVa().
| char* name |
Definition at line 23 of file log.c.
Referenced by addToBigBundleList(), cdaLoadOne(), cgiFromCommandLine(), cgiOneChoice(), clumpTargetName(), dnaLoadNextFromStack(), dnaLoadSingle(), expandEntities(), faFastReadNext(), faMixedSpeedReadNext(), faReadAllMixableInLf(), faReadMixedNext(), findLowType(), fofMake(), gfClumpDump(), gfFileCacheFreeEl(), gfPcrGetRanges(), hashTwoColumnFile(), htmlFormVarAddValue(), htmlTagScan(), listDir(), mafFromAxt(), mafMayOpen(), mafNextWithPos(), makeIndex(), makeOffsetList(), newWormFeature(), nextSeqFromMem(), nibLoadAllMasked(), outputBed(), outputFa(), outputPsl(), parseAnOption(), parseCookie(), parseElement(), parseEntity(), parseFacility(), raFoldIn(), raFoldInOneRetName(), readPslToBinKeeper(), scanChromOffsetFile(), semiUniqName(), seqClumpToRangeList(), setProgram(), stringToSlNames(), twoBitFromFile(), twoBitOpen(), twoBitSeqNames(), warnAboutDupes(), wormChromPartExonsUpper(), wormGdfGenesInRange(), and wormGeneFirstOrfName().
1.5.2