OpenBarnyard
 
Loading...
Searching...
No Matches
TLogFile Class Reference

#include <TLogFile.h>

Public Types

enum class  Error { OK , OpenFile , AlreadyCreated }
 

Public Member Functions

 TLogFile ()
 
 ~TLogFile ()
 
Error Create (const TCHAR *fileName, const TCHAR *str2, TBOOL writeExisting)
 
void Close ()
 
void RecalcLevel ()
 
void Print (const TCHAR *format,...)
 
void Log (TUtil::LogType type, const TCHAR *str1, const TCHAR *str2, const TCHAR *format,...)
 
void Down ()
 
void Up ()
 
void AllowIndentation (TBOOL a_bAllow)
 
TBOOL GetAllowIndentation ()
 
void SetSimpleMode (TBOOL a_bEnable)
 
TBOOL IsSimpleMode ()
 
TINT GetTypeCount (TUtil::LogType a_eType) const
 
TINT GetTotalLogCount () const
 
const TCHARGetLevelString () const
 

Detailed Description

Definition at line 18 of file TLogFile.h.

Member Enumeration Documentation

◆ Error

enum class TLogFile::Error
strong
Enumerator
OK 
OpenFile 
AlreadyCreated 

Definition at line 24 of file TLogFile.h.

25 {
26 OK,
27 OpenFile,
28 AlreadyCreated
29 };

Constructor & Destructor Documentation

◆ TLogFile()

TLogFile::TLogFile ( )

Definition at line 13 of file TLogFile.cpp.

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}
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24

◆ ~TLogFile()

TLogFile::~TLogFile ( )

Definition at line 25 of file TLogFile.cpp.

26{
27 TASSERT( TNULL == m_pFile, "TFile must be NULL" );
28 Close();
29}
#define TASSERT(X,...)
Definition Defines.h:138
void Close()
Definition TLogFile.cpp:69

Member Function Documentation

◆ AllowIndentation()

void TLogFile::AllowIndentation ( TBOOL a_bAllow)
inline

Definition at line 46 of file TLogFile.h.

46{ m_bAllowIndentation = a_bAllow; }

◆ Close()

void TLogFile::Close ( )

Definition at line 69 of file TLogFile.cpp.

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}
void Print(const TCHAR *format,...)
Definition TLogFile.cpp:99
void RecalcLevel()
Definition TLogFile.cpp:86
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

◆ Create()

TLogFile::Error TLogFile::Create ( const TCHAR * fileName,
const TCHAR * str2,
TBOOL writeExisting )

Definition at line 31 of file TLogFile.cpp.

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}
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
#define TIMPLEMENT_D(DESC)
Definition Defines.h:137
static TFile * Create(const TString8 &a_rcFilename, TFILEMODE a_eMode=TFILEMODE_READ)
Definition TFile.cpp:29
static const TCHAR * GetTime()
Definition TUtil_Win.cpp:54

◆ Down()

void TLogFile::Down ( )

Definition at line 165 of file TLogFile.cpp.

166{
167 m_curLevel--;
168 RecalcLevel();
169}

◆ GetAllowIndentation()

TBOOL TLogFile::GetAllowIndentation ( )
inline

Definition at line 47 of file TLogFile.h.

47{ return m_bAllowIndentation; }

◆ GetLevelString()

const TCHAR * TLogFile::GetLevelString ( ) const
inline

Definition at line 54 of file TLogFile.h.

54{ return m_LevelString; }

◆ GetTotalLogCount()

TINT TLogFile::GetTotalLogCount ( ) const
inline

Definition at line 53 of file TLogFile.h.

53{ return m_iTotalLogCount; }

◆ GetTypeCount()

TINT TLogFile::GetTypeCount ( TUtil::LogType a_eType) const
inline

Definition at line 52 of file TLogFile.h.

52{ return m_typeCounts[ a_eType ]; }

◆ IsSimpleMode()

TBOOL TLogFile::IsSimpleMode ( )
inline

Definition at line 50 of file TLogFile.h.

50{ return m_bIsSimpleMode; }

◆ Log()

void TLogFile::Log ( TUtil::LogType type,
const TCHAR * str1,
const TCHAR * str2,
const TCHAR * format,
... )

Definition at line 122 of file TLogFile.cpp.

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}
char TCHAR
Definition Typedefs.h:20
static TINT FormatV(TCHAR *a_pcString, TINT size, const TCHAR *a_pcFormat, va_list args)
Definition T2String8.cpp:22
static TCHAR * GetTempString8()

◆ Print()

void TLogFile::Print ( const TCHAR * format,
... )

Definition at line 99 of file TLogFile.cpp.

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}

◆ RecalcLevel()

void TLogFile::RecalcLevel ( )

Definition at line 86 of file TLogFile.cpp.

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}
size_t TSIZE
Definition Typedefs.h:9
TFORCEINLINE const T & Max(const T &a, const T &b)
TFORCEINLINE const T & Min(const T &a, const T &b)

◆ SetSimpleMode()

void TLogFile::SetSimpleMode ( TBOOL a_bEnable)
inline

Definition at line 49 of file TLogFile.h.

49{ m_bIsSimpleMode = a_bEnable; }

◆ Up()

void TLogFile::Up ( )

Definition at line 171 of file TLogFile.cpp.

172{
173 m_curLevel++;
174 RecalcLevel();
175}

The documentation for this class was generated from the following files: