Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

LogFile.cc

Go to the documentation of this file.
00001 /*
00002 
00003     Log file class
00004     Copyright (C) 1999-2001 Jussi Laako
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 

Generated on Sun Oct 26 19:11:21 2003 for HASAS by doxygen 1.3.3