2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * INCLUDES ___________________________________________________________________
18 #include <afsconfig.h>
19 #include <afs/param.h>
25 #include <afs\afs_utilAdmin.h>
31 #include <WINNT\talocale.h>
36 * MEMBER FUNCTIONS _________________________________________________________
50 BOOL LOGFILE::Open(const char *pszLogFilePath,
51 LOGFILE_OPEN_MODE eOpenMode,
52 LOGFILE_TIMESTAMP_MODE eTimeStampMode)
56 m_eTimeStampMode = eTimeStampMode;
58 if (eOpenMode == OM_OVERWRITE)
63 strcpy(m_szPath, pszLogFilePath);
65 m_fp = fopen(pszLogFilePath, pszOpenMode);
67 if (m_eTimeStampMode != TSM_NEVER)
69 fprintf(m_fp, "Log file open.\r\n");
82 if (m_eTimeStampMode != TSM_NEVER)
84 fprintf(m_fp, "Closing log file.\r\n");
85 nResult = fclose(m_fp);
90 return (nResult == 0);
93 BOOL LOGFILE::Write(const char *pszEntry, ...)
95 static BOOL bTimestampNextLine = TRUE;
100 if (bTimestampNextLine && (m_eTimeStampMode == TSM_EACH_ENTRY))
105 va_start(args, pszEntry);
107 int nWritten = vfprintf(m_fp, pszEntry, args);
113 // Don't timestamp next line unless current line ended with a newline
114 bTimestampNextLine = (pszEntry[strlen(pszEntry) - 1] == '\n');
116 return (nWritten > 0);
119 BOOL LOGFILE::WriteError(const char *pszMsg, DWORD nErrorCode, ...)
124 if (m_eTimeStampMode == TSM_EACH_ENTRY)
129 va_start(args, nErrorCode);
131 int nWritten = vfprintf(m_fp, pszMsg, args);
137 afs_status_t nStatus;
138 const char *pszErrorText;
140 int nResult = util_AdminErrorCodeTranslate(nErrorCode, TaLocale_GetLanguage(), &pszErrorText, &nStatus);
142 fprintf(m_fp, ": (0x%lx), %s.\r\n", nErrorCode, pszErrorText);
144 fprintf(m_fp, ": (0x%lx).\r\n", nErrorCode);
148 return (nWritten > 0);
151 BOOL LOGFILE::WriteTimeStamp()
156 char szTime[64], szDate[64];
161 fprintf(m_fp, "%s %s: ", szTime, szDate);
166 BOOL LOGFILE::WriteBoolResult(BOOL bResult)
171 fprintf(m_fp, "%s.\r\n", bResult ? "Yes" : "No");
178 BOOL LOGFILE::WriteMultistring(const char *pszMultiStr)
183 for (const char *p = pszMultiStr; *p; p += strlen(p))