OpenBarnyard
 
Loading...
Searching...
No Matches
TLogFile.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TLogFile.h"
3#include "File/TFile.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
14{
15 m_pFile = TNULL;
16 m_iTotalLogCount = 0;
17 m_bIsSimpleMode = TFALSE;
18 m_curLevel = 0;
19 *m_LevelString = 0;
20 *m_typeCounts = 0;
21 m_unk2 = TNULL;
22 m_unk3 = 0;
23}
24
26{
27 TASSERT( TNULL == m_pFile, "TFile must be NULL" );
28 Close();
29}
30
31TLogFile::Error TLogFile::Create( const TCHAR* fileName, const TCHAR* str2, TBOOL writeExisting )
32{
33 TASSERT( TNULL == m_pFile );
34
35 if ( m_pFile != TNULL )
36 {
38 }
39
40 TIMPLEMENT_D( "uVar1 = FUN_008289A0(fileName);" );
41 TIMPLEMENT_D( "FUN_00828A40(uVar1);" );
42
43 TFILEMODE fileMode = writeExisting ?
46
47 m_pFile = TFile::Create( fileName, fileMode );
48
49 if ( m_pFile == TNULL )
50 {
51 return Error::OpenFile;
52 }
53
54 if ( writeExisting )
55 {
56 m_pFile->Seek( 0, TSEEK_END );
57 }
58
59 m_iTotalLogCount = 0;
60 *m_LevelString = 0;
61 m_curLevel = 0;
62
63 m_pFile->CPrintf( "Log created [%s]:[%s]: %s\n", fileName, str2, TUtil::GetTime() );
64 m_pFile->CPrintf( "Compilation: %s\n", __TIMESTAMP__ );
65
66 return Error::OK;
67}
68
70{
71 m_curLevel = 0;
73
74 for ( int i = TUtil::LogType_Info; i < TUtil::LogType_NUMOF; i++ )
75 {
76 Print( "%s count = %d\n", TUtil::LogTypeToString( TUtil::LogType( i ) ), m_typeCounts[ i ] );
77 }
78
79 if ( m_pFile != TNULL )
80 {
81 m_pFile->Destroy();
82 m_pFile = TNULL;
83 }
84}
85
87{
88 m_curLevel = TMath::Min<TUINT32>( m_curLevel, cLevelMax );
89 m_curLevel = TMath::Max<TUINT32>( m_curLevel, 0 );
90
91 for ( TSIZE i = 0; i < m_curLevel; i++ )
92 {
93 m_LevelString[ i ] = 9;
94 }
95
96 m_LevelString[ m_curLevel ] = 0;
97}
98
99void TLogFile::Print( const TCHAR* format, ... )
100{
101 if ( m_pFile != TNULL )
102 {
103 va_list args;
104 va_start( args, format );
105
106 TCHAR str[ 1024 ];
107 T2String8::FormatV( str, sizeof( str ), format, args );
108
109 va_end( args );
110
111 if ( m_bAllowIndentation )
112 {
113 m_pFile->CPrintf( "%s%s", m_LevelString, str );
114 }
115 else
116 {
117 m_pFile->CPrintf( str );
118 }
119 }
120}
121
122void TLogFile::Log( TUtil::LogType type, const TCHAR* str1, const TCHAR* str2, const TCHAR* format, ... )
123{
124 if ( m_pFile != TNULL )
125 {
126 if ( m_bIsSimpleMode )
127 {
128 if ( m_bAllowIndentation )
129 {
130 m_pFile->CPrintf(
131 "%d [%s]: %s",
132 m_iTotalLogCount,
134 m_LevelString
135 );
136 }
137 }
138 else
139 {
140 TCHAR strTime[ 128 ];
141 _strtime( strTime );
142
143 m_pFile->CPrintf(
144 "%d [%s] [%s]: %s: %s: %s",
145 m_iTotalLogCount,
147 strTime,
148 str1,
149 str2 != TNULL ? str2 : "",
150 !m_bAllowIndentation ? m_LevelString : ""
151 );
152 }
153
154 va_list args;
155 va_start( args, format );
157 m_pFile->CPrintf( TStringManager::GetTempString8() );
158 va_end( args );
159
160 m_typeCounts[ type ]++;
161 m_iTotalLogCount++;
162 }
163}
164
166{
167 m_curLevel--;
168 RecalcLevel();
169}
170
172{
173 m_curLevel++;
174 RecalcLevel();
175}
176
Core file system interface for the Toshi engine.
TUINT16 TFILEMODE
Definition TFile.h:35
@ TSEEK_END
Definition TFile.h:32
@ TFILEMODE_NOBUFFER
Definition TFile.h:42
@ TFILEMODE_WRITE
Definition TFile.h:39
@ TFILEMODE_CREATENEW
Definition TFile.h:41
Logging system for the Toshi engine.
#define TASSERT(X,...)
Definition Defines.h:138
#define TIMPLEMENT_D(DESC)
Definition Defines.h:137
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
size_t TSIZE
Definition Typedefs.h:9
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
bool TBOOL
Definition Typedefs.h:6
TFORCEINLINE const T & Max(const T &a, const T &b)
TFORCEINLINE const T & Min(const T &a, const T &b)
static TFile * Create(const TString8 &a_rcFilename, TFILEMODE a_eMode=TFILEMODE_READ)
Definition TFile.cpp:29
void Print(const TCHAR *format,...)
Definition TLogFile.cpp:99
void Log(TUtil::LogType type, const TCHAR *str1, const TCHAR *str2, const TCHAR *format,...)
Definition TLogFile.cpp:122
void Down()
Definition TLogFile.cpp:165
Error Create(const TCHAR *fileName, const TCHAR *str2, TBOOL writeExisting)
Definition TLogFile.cpp:31
void RecalcLevel()
Definition TLogFile.cpp:86
void Close()
Definition TLogFile.cpp:69
void Up()
Definition TLogFile.cpp:171
static TINT FormatV(TCHAR *a_pcString, TINT size, const TCHAR *a_pcFormat, va_list args)
Definition T2String8.cpp:22
static TCHAR * GetTempString8()
static constexpr const TCHAR * LogTypeToString(LogType a_eType)
Definition TUtil.h:36
LogType
Definition TUtil.h:21
@ LogType_Info
Definition TUtil.h:22
@ LogType_NUMOF
Definition TUtil.h:26
static const TCHAR * GetTime()
Definition TUtil_Win.cpp:54