From: Jeffrey Altman Date: Tue, 21 Jun 2005 21:22:12 +0000 (+0000) Subject: STABLE14-threaded-logging-20050619 X-Git-Tag: openafs-devel-1_3_85~45 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=f14746ff72505100f412604f9e199bea7f7ada3d;p=packages%2Fo%2Fopenafs.git STABLE14-threaded-logging-20050619 update logging to be able to show threads (cherry picked from commit 9b1430c2d028dd38ce7392297cfe572d82a4c173) --- diff --git a/src/util/afsutil.h b/src/util/afsutil.h index be42efe55..335fd5e71 100644 --- a/src/util/afsutil.h +++ b/src/util/afsutil.h @@ -25,12 +25,15 @@ #include #include extern int LogLevel; +extern int mrafsStyleLogs; #ifndef AFS_NT40_ENV extern int serverLogSyslog; extern int serverLogSyslogFacility; extern char *serverLogSyslogTag; #endif extern void vFSLog(const char *format, va_list args); +extern void SetLogThreadNameProgram(char *(*func) () ); + /*@printflike@*/ extern void FSLog(const char *format, ...); #define ViceLog(level, str) if ((level) <= LogLevel) (FSLog str) #define vViceLog(level, str) if ((level) <= LogLevel) (vFSLog str) diff --git a/src/util/serverLog.c b/src/util/serverLog.c index 2f1e78b37..cbb4f0a50 100644 --- a/src/util/serverLog.c +++ b/src/util/serverLog.c @@ -70,7 +70,7 @@ static pthread_mutex_t serverLogMutex; #define O_NONBLOCK 0 #endif -char *(*threadNameProgram) (); +static char *(*threadNameProgram) () = NULL; static int serverLogFD = -1; @@ -83,9 +83,16 @@ char *serverLogSyslogTag = 0; #include int LogLevel; int mrafsStyleLogs = 0; +static int threadIdLogs = 0; int printLocks = 0; static char ourName[MAXPATHLEN]; +void +SetLogThreadNameProgram(char *(*func) () ) +{ + threadNameProgram = func; +} + void WriteLogBuffer(char *buf, afs_uint32 len) { @@ -110,12 +117,14 @@ vFSLog(const char *format, va_list args) timeStamp[24] = ' '; /* ts[24] is the newline, 25 is the null */ info = &timeStamp[25]; - if (mrafsStyleLogs) { + if (mrafsStyleLogs || threadIdLogs) { name = (*threadNameProgram) (); + if (name) { (void)afs_snprintf(info, (sizeof tbuffer) - strlen(tbuffer), "[%s] ", name); info += strlen(info); } + } (void)afs_vsnprintf(info, (sizeof tbuffer) - strlen(tbuffer), format, args); @@ -171,8 +180,20 @@ SetDebug_Signal(int signo) if (LogLevel > 0) { LogLevel *= 5; + +#if defined(AFS_PTHREAD_ENV) + if (LogLevel > 999 && threadNameProgram != NULL && + threadIdLogs == 0) { + threadIdLogs = 1; + } +#endif } else { LogLevel = 1; + +#if defined(AFS_PTHREAD_ENV) + if (threadIdLogs == 1) + threadIdLogs = 0; +#endif } printLocks = 2; #if defined(AFS_PTHREAD_ENV) @@ -203,6 +224,10 @@ ResetDebug_Signal(int signo) * this signal handler * needs to be set * again */ +#if defined(AFS_PTHREAD_ENV) + if (threadIdLogs == 1) + threadIdLogs = 0; +#endif if (mrafsStyleLogs) OpenLog((char *)&ourName); } /*ResetDebug_Signal */ @@ -247,8 +272,9 @@ OpenLog(const char *fileName) #endif if (mrafsStyleLogs) { - time_t t = Start.tv_sec; + time_t t; TM_GetTimeOfDay(&Start, 0); + t = Start.tv_sec; TimeFields = localtime(&t); if (fileName) { if (strncmp(fileName, (char *)&ourName, strlen(fileName))) diff --git a/src/viced/viced.c b/src/viced/viced.c index 85119aba0..d6e3a6970 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -88,7 +88,6 @@ RCSID #include "host.h" #ifdef AFS_PTHREAD_ENV #include "softsig.h" -char *(*threadNameProgram) (); #endif #if defined(AFS_SGI_ENV) #include "sys/schedctl.h" @@ -1105,6 +1104,10 @@ ParseArgs(int argc, char *argv[]) serverLogSyslogFacility = atoi(argv[i] + 8); } #endif + else if (strcmp(argv[i], "-mrafslogs") == 0) { + /* set syslog logging flag */ + mrafsStyleLogs = 1; + } else { return (-1); } @@ -1726,8 +1729,8 @@ main(int argc, char *argv[]) V_BreakVolumeCallbacks = BreakVolumeCallBacksLater; } -#if defined(AFS_PTHREAD_ENV) - threadNameProgram = threadName; +#ifdef AFS_PTHREAD_ENV + SetLogThreadNameProgram( threadName ); #endif /* initialize libacl routines */