-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathErrLog.cpp
More file actions
133 lines (103 loc) · 3.42 KB
/
ErrLog.cpp
File metadata and controls
133 lines (103 loc) · 3.42 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************************
// Copyright (c) 2000, Robert Umbehant
// mailto:rumbehant@wheresjames.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later
// version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307 USA
//
*******************************************************************/
// ErrLog.cpp: implementation of the CErrLog class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CErrLog::CErrLog()
{_STT();
m_bEnable = TRUE;
}
CErrLog::~CErrLog()
{_STT();
Destroy();
}
void CErrLog::Destroy()
{_STT();
CLList::Destroy();
}
BOOL CErrLog::InitObject( void *node )
{_STT();
// Do initiailization
if ( !CLList::InitObject( node ) ) return FALSE;
LPERRORITEMINFO peii = (LPERRORITEMINFO)node;
if ( peii == NULL ) return FALSE;
peii->sFile = new CStr;
if ( peii->sFile == NULL ) return FALSE;
peii->sFunction = new CStr;
if ( peii->sFunction == NULL ) return FALSE;
return TRUE;
}
void CErrLog::DeleteObject( void *node )
{_STT();
LPERRORITEMINFO peii = (LPERRORITEMINFO)node;
if ( peii == NULL ) return;
// Lose the file
_PTR_DELETE( peii->sFile );
_PTR_DELETE( peii->sFunction );
CLList::DeleteObject( node );
}
HRESULT _cdecl CErrLog::Add( LPCTSTR pFile, DWORD dwLine, LPCTSTR pFunction,
DWORD dwSeverity, DWORD dwErrCode, LPCTSTR pStr, ... )
{_STT();
if ( !m_bEnable )
return dwErrCode;
try // This could GPF if caller screws up
{
char str[ CWF_STRSIZE * 4 ] = { 0 };
try
{
// Create error string
LPVOID *args = ( (LPVOID*)&pStr ) + 1;
if ( pStr != NULL )
wvsprintf( str, pStr, (va_list)args );
else strcpy( str, "< NULL >" );
} catch( ... )
{ try { if ( pStr != NULL ) strcpy( str, pStr );
} catch( ... )
{ strcpy( str, "Bad params passed to log file." );
} // end catch
} // end catch
// Create error structure
LPERRORITEMINFO peii = (LPERRORITEMINFO)New( NULL, (LPVOID)dwErrCode, str );
if ( peii == NULL ) return dwErrCode;
// Save error location information
if ( pFile ) *peii->sFile = pFile; else *peii->sFile = "";
peii->dwLine = dwLine;
if ( pFunction ) *peii->sFunction = pFunction; else *peii->sFunction = "";
// Save error info
peii->dwCode = dwErrCode;
peii->dwSeverity = dwSeverity;
// Save the time of the error
peii->dwTime = (DWORD)time( NULL );
} // end try
catch( ... ) { ASSERT( 0 ); return dwErrCode; }
return dwErrCode;
}