00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <errno.h>
00025 #include <time.h>
00026 #include <string.h>
00027
00028 #include "LogFile.hh"
00029
00030
00031 clLogFile::clLogFile()
00032 {
00033 bOk = false;
00034 iEC = LOGFILE_NOERROR;
00035 }
00036
00037
00038 clLogFile::clLogFile(const char *cpLogFile)
00039 {
00040 bOk = false;
00041 iEC = LOGFILE_NOERROR;
00042 Open(cpLogFile);
00043 }
00044
00045
00046 clLogFile::~clLogFile()
00047 {
00048 if (bOk) fclose(FLog);
00049 }
00050
00051
00052 bool clLogFile::Open(const char *cpLogFile)
00053 {
00054 FLog = fopen(cpLogFile, "at");
00055 if (FLog != NULL)
00056 {
00057 bOk = true;
00058 fprintf(FLog, "\n");
00059 }
00060 else
00061 {
00062 bOk = false;
00063 iEC = errno;
00064 }
00065 return bOk;
00066 }
00067
00068
00069 bool clLogFile::Add(char cLogMark, const char *cpLogEntry)
00070 {
00071 if (!bOk) return false;
00072 Time();
00073 if (fprintf(FLog, "%c %s %s\n", cLogMark, cpTime, cpLogEntry) <= 0)
00074 {
00075 return false;
00076 }
00077 fflush(FLog);
00078 return true;
00079 }
00080
00081
00082 bool clLogFile::Add(char cLogMark, const char *cpLogEntry, int iErrno)
00083 {
00084 if (!bOk) return false;
00085 Time();
00086 if (fprintf(FLog, "%c %s %s: (%i) %s\n", cLogMark, cpTime, cpLogEntry,
00087 iErrno, strerror(iErrno)) <= 0)
00088 {
00089 return false;
00090 }
00091 fflush(FLog);
00092 return true;
00093 }
00094
00095
00096 void clLogFile::Time()
00097 {
00098 time_t ttTime;
00099 struct tm *spTM;
00100
00101 ttTime = time(NULL);
00102 spTM = localtime(&ttTime);
00103 strftime(cpTime, 20, "%Y/%m/%d %H:%M:%S", spTM);
00104 }
00105