-
Notifications
You must be signed in to change notification settings - Fork 1
/
Log.cpp
87 lines (65 loc) · 1.92 KB
/
Log.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Log.cpp: implementation of the CLog class.
//
//////////////////////////////////////////////////////////////////////
# include "Log.h"
# include "Exception.h"
# include <fstream>
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLog::CLog()
{
}
CLog::~CLog()
{
}
/*********************************************************************
NAME : SetLogFileName
DESCRIPTION: Initializes the name of the log file.
PARAMETER : szFileName : Character string containing log file name
RETURN : void
EXCEPTION : CException.
*********************************************************************/
void CLog::SetLogFileName (char szFileName[256])
{
ofstream logFile;
/********************************************************
STRATEGY:
1. Set the filename variable to the name that we have been
passed.
2. Test that the name that we have been passed is usable.
If not then throw an exception.
********************************************************/
// 1.
strcpy (this->szFileName, szFileName);
// 2.
logFile.open(this->szFileName);
if (!logFile)
{
throw new CException();
}
}
/*********************************************************************
NAME : Write
DESCRIPTION: Writes a character string into the log file
PARAMETER : szString : Character string to be written
RETURN : void
EXCEPTION : NONE.
*********************************************************************/
void CLog::Write (char* szString)
{
ofstream logFile;
/********************************************************
STRATEGY:
1. Open the logfile in append mode.
2. Write into the logfile.
3. Close the log file.
********************************************************/
// 1.
logFile.open(this->szFileName, ios::out|ios::app);
// 2.
logFile << szString;
// 3.
logFile.close();
}