OpenClonk
C4Log.cpp File Reference
#include "C4Include.h"
#include "lib/C4Log.h"
#include "c4group/C4Components.h"
#include "editor/C4Console.h"
#include "game/C4GraphicsSystem.h"
#include "graphics/C4Shader.h"
#include "gui/C4GameLobby.h"
#include "lib/C4LogBuf.h"
#include "network/C4Network2.h"
#include "platform/C4Window.h"
#include "script/C4AulDebug.h"
Include dependency graph for C4Log.cpp:

Go to the source code of this file.

Functions

bool OpenLog ()
 
bool OpenExtraLogs ()
 
bool CloseLog ()
 
int GetLogFD ()
 
bool LogSilent (const char *szMessage, bool fConsole)
 
bool LogSilent (const char *szMessage)
 
bool Log (const char *szMessage)
 
bool LogFatal (const char *szMessage)
 
void ResetFatalError ()
 
const char * GetFatalError ()
 
bool LogF (const char *strMessage,...)
 
bool LogSilentF (const char *strMessage,...)
 
bool DebugLog (const char *strMessage)
 
bool DebugLogF (const char *strMessage ...)
 
size_t GetLogPos ()
 
bool GetLogSection (size_t iStart, size_t iLength, StdStrBuf &rsOut)
 
bool ShaderLog (const char *szMessage)
 
bool ShaderLogF (const char *strMessage ...)
 

Variables

FILE * C4LogFile =nullptr
 
FILE * C4ShaderLogFile = nullptr
 
time_t C4LogStartTime
 
StdStrBuf sLogFileName
 
StdStrBuf sFatalError
 
int iDisableLog = 0
 

Function Documentation

◆ CloseLog()

bool CloseLog ( )

Definition at line 107 of file C4Log.cpp.

108 {
109  // close
110  if (C4ShaderLogFile) fclose(C4ShaderLogFile);
111  C4ShaderLogFile = nullptr;
112  if (C4LogFile) fclose(C4LogFile);
113  C4LogFile = nullptr;
114  // ok
115  return true;
116 }
FILE * C4ShaderLogFile
Definition: C4Log.cpp:42
FILE * C4LogFile
Definition: C4Log.cpp:41

References C4LogFile, and C4ShaderLogFile.

Referenced by C4Application::~C4Application().

Here is the caller graph for this function:

◆ DebugLog()

bool DebugLog ( const char *  strMessage)

Definition at line 282 of file C4Log.cpp.

283 {
284  if (Game.DebugMode)
285  return Log(strMessage);
286  else
287  return LogSilent(strMessage);
288 }
C4Game Game
Definition: C4Globals.cpp:52
bool LogSilent(const char *szMessage, bool fConsole)
Definition: C4Log.cpp:126
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
bool DebugMode
Definition: C4Game.h:145

References C4Game::DebugMode, Game, Log(), and LogSilent().

Referenced by DebugLogF(), C4AulScriptContext::dump(), C4Game::LoadScenarioComponents(), C4Game::LoadScenarioSection(), OpenExtraLogs(), C4InteractiveThread::ProcessEvents(), and C4PropListScen::SetPropertyByS().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DebugLogF()

bool DebugLogF ( const char *  strMessage ...)

Definition at line 290 of file C4Log.cpp.

291 {
292  va_list args; va_start(args, strMessage);
293  StdStrBuf Buf;
294  Buf.FormatV(strMessage, args);
295  return DebugLog(Buf.getData());
296 }
bool DebugLog(const char *strMessage)
Definition: C4Log.cpp:282
void FormatV(const char *szFmt, va_list args)
Definition: StdBuf.cpp:182
const char * getData() const
Definition: StdBuf.h:442

References DebugLog(), StdStrBuf::FormatV(), and StdStrBuf::getData().

Referenced by C4MaterialMap::CrossMapMaterials(), C4ScenarioListLoader::SubFolder::DoLoadContents(), C4ScenarioListLoader::RegularFolder::DoLoadContents(), C4RoundResults::EvaluateGame(), C4GameObjects::FixObjectOrder(), C4AulExec::FnTranslate(), C4TextureMap::GetIndex(), C4TextureMap::GetIndexMatTex(), C4Object::GetInfoString(), C4TexMapEntry::Init(), C4ParticleDef::Load(), C4MapFolderData::Load(), C4DefGraphics::LoadBitmap(), C4Def::LoadDefCore(), C4TextureMap::LoadMap(), C4DefGraphics::LoadMesh(), C4Game::LoadScenarioSection(), C4DefGraphics::LoadSkeleton(), C4SoundSystem::NewEffect(), C4GameObjects::PostLoad(), C4MaterialReaction::ResolveScriptFuncs(), C4Landscape::SetTextureIndex(), StdCompilerWarnCallback(), and StdMeshMaterialParserCtx::WarningNotSupported().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFatalError()

const char* GetFatalError ( )

Definition at line 257 of file C4Log.cpp.

258 {
259  return sFatalError.getData();
260 }
StdStrBuf sFatalError
Definition: C4Log.cpp:46

References StdStrBuf::getData(), and sFatalError.

Referenced by C4Startup::DoStartup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLogFD()

int GetLogFD ( )

Definition at line 118 of file C4Log.cpp.

119 {
120  if (C4LogFile)
121  return fileno(C4LogFile);
122  else
123  return -1;
124 }

References C4LogFile.

◆ GetLogPos()

size_t GetLogPos ( )

Definition at line 298 of file C4Log.cpp.

299 {
300  // get current log position
301  return FileSize(sLogFileName.getData());
302 }
StdStrBuf sLogFileName
Definition: C4Log.cpp:44
size_t FileSize(const char *fname)

References FileSize(), StdStrBuf::getData(), and sLogFileName.

Referenced by C4Game::Clear(), and C4Game::Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLogSection()

bool GetLogSection ( size_t  iStart,
size_t  iLength,
StdStrBuf rsOut 
)

Definition at line 304 of file C4Log.cpp.

305 {
306  if (!iLength) { rsOut.Clear(); return true; }
307  // read section from log file
308  StdStrBuf BufOrig;
309  if (!BufOrig.LoadFromFile(sLogFileName.getData())) return false;
310  char *szBuf = BufOrig.getMData();
311  size_t iSize = BufOrig.getSize(); // size excluding terminator
312  // reduce to desired buffer section
313  if (iStart > iSize) iStart = iSize;
314  if (iStart + iLength > iSize) iLength = iSize - iStart;
315  szBuf += iStart; szBuf[iLength] = '\0';
316  // strip timestamps; convert linebreaks to Clonk-linebreaks '|'
317  char *szPosWrite=szBuf; const char *szPosRead=szBuf;
318  while (*szPosRead)
319  {
320  // skip timestamp
321  if (*szPosRead == '[')
322  while (*szPosRead && *szPosRead != ']') { --iSize; ++szPosRead; }
323  // skip whitespace behind timestamp
324  if (!*szPosRead) break;
325  szPosRead++;
326  // copy data until linebreak
327  size_t iLen=0;
328  while (*szPosRead && *szPosRead != 0x0d && *szPosRead != 0x0a)
329  { ++szPosRead; ++iLen; }
330  if (iLen && szPosRead-iLen != szPosWrite) memmove(szPosWrite, szPosRead-iLen, iLen);
331  szPosWrite += iLen;
332  // skip additional linebreaks
333  while (*szPosRead == 0x0d || *szPosRead == 0x0a) ++szPosRead;
334  // write a Clonk-linebreak
335  if (*szPosRead) *szPosWrite++ = '|';
336  }
337  // done; create string buffer from data
338  rsOut.Copy(szBuf, szPosWrite - szBuf);
339  // done, success
340  return true;
341 }
int iSize
Definition: TstC4NetIO.cpp:32
size_t getSize() const
Definition: StdBuf.h:444
char * getMData()
Definition: StdBuf.h:443
void Copy()
Definition: StdBuf.h:467
bool LoadFromFile(const char *szFile)
Definition: StdBuf.cpp:73
void Clear()
Definition: StdBuf.h:466

References StdStrBuf::Clear(), StdStrBuf::Copy(), StdStrBuf::getData(), StdStrBuf::getMData(), StdStrBuf::getSize(), iSize, StdStrBuf::LoadFromFile(), and sLogFileName.

Referenced by C4Startup::DoStartup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Log()

bool Log ( const char *  szMessage)

Definition at line 204 of file C4Log.cpp.

205 {
206  if (!Application.AssertMainThread()) return false;
207  if (iDisableLog) return true;
208  // security
209  if (!szMessage) return false;
210 
211 #ifndef NOAULDEBUG
212  // Pass on to debugger
213  if (C4AulDebug *pDebug = C4AulDebug::GetDebugger())
214  pDebug->OnLog(szMessage);
215 #endif
216  // Pass on to console
217  Console.Out(szMessage);
218  // pass on to lobby
220  if (pLobby) pLobby->OnLog(szMessage);
221 
222  // Add message to log buffer
223  bool fNotifyMsgBoard = false;
225  {
226  ::GraphicsSystem.MessageBoard->AddLog(szMessage);
227  fNotifyMsgBoard = true;
228  }
229 
230  // log
231  LogSilent(szMessage, true);
232 
233  // Notify message board
234  if (fNotifyMsgBoard) ::GraphicsSystem.MessageBoard->LogNotify();
235 
236  return true;
237 }
C4Console Console
Definition: C4Globals.cpp:45
C4Application Application
Definition: C4Globals.cpp:44
C4Network2 Network
Definition: C4Globals.cpp:53
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
int iDisableLog
Definition: C4Log.cpp:202
bool AssertMainThread()
Definition: C4App.h:123
static C4AulDebug * GetDebugger()
Definition: C4AulDebug.h:31
void Out(const char *message)
Definition: C4Console.cpp:684
void OnLog(const char *szLogMsg, DWORD dwClr=C4GUI_LogFontClr)
std::unique_ptr< C4MessageBoard > MessageBoard
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216

References Application, C4AbstractApp::AssertMainThread(), Console, C4AulDebug::GetDebugger(), C4Network2::GetLobby(), GraphicsSystem, iDisableLog, LogSilent(), C4GraphicsSystem::MessageBoard, Network, C4GameLobby::MainDlg::OnLog(), and C4ConsoleGUI::Out().

Referenced by C4GameLobby::Countdown::Abort(), C4ClientList::Add(), C4Network2ResList::AddByFile(), C4Network2ResList::AddByGroup(), C4PlayerInfoList::AssignPlayerIDs(), C4Network2IO::Broadcast(), C4ClientPlayerInfos::C4ClientPlayerInfos(), C4GamePadControl::C4GamePadControl(), C4Game::CanQuickSave(), C4Playback::Check(), C4ObjectList::CheckSort(), C4Game::Clear(), C4Application::Clear(), ConsoleDlgProc(), C4AbstractApp::Copy(), C4GameLobby::Countdown::Countdown(), CStdGL::CreateContext(), C4Network2::CreateDynamic(), DebugLog(), C4Network2Res::Derive(), C4Game::DoGameOver(), C4Application::DoInit(), C4Network2::DoLobby(), C4GraphicsSystem::DoSaveScreenshot(), C4Player::Eliminate(), C4Draw::Error(), C4Game::Evaluate(), C4GameControl::ExecControl(), C4GameControl::ExecControlPacket(), C4Network2::FinalInit(), C4Network2Res::GetStandalone(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4Game::Init(), C4Game::InitControl(), C4Game::InitDefs(), C4Game::InitGame(), C4Game::InitNetworkFromAddress(), C4PlayerList::Join(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuth(), C4Network2::LeaguePlrAuthCheck(), C4Network2::LeagueStart(), C4Network2::LeagueUpdateProcessReply(), C4Network2::LeagueWaitNotBusy(), C4AulDebug::Listen(), C4SoundEffect::Load(), C4ParticleDef::Load(), C4MaterialMap::Load(), C4Config::Load(), C4Game::LoadAdditionalSystemGroup(), C4Extra::LoadDef(), C4Language::LoadLanguage(), C4GameLobby::LobbyError(), LogF(), LogFatal(), main(), C4MainMenu::MenuCommand(), C4Network2::OnClientDisconnect(), C4GameOptionButtons::OnCommentSet(), C4GameLobby::Countdown::OnSec1Timer(), C4Game::OpenScenario(), C4Network2Res::OptimizeStandalone(), C4Application::ParseCommandLine(), C4Application::PreInit(), CStdGL::PrepareMaterial(), C4MessageInput::ProcessCommand(), C4InteractiveThread::ProcessEvents(), ProcessGroup(), C4MessageInput::ProcessInput(), C4Game::QuickSave(), C4Game::ReloadDef(), C4PlayerList::RemoveAtClient(), C4PlayerList::RemoveAtRemoteClient(), C4PlayerList::RemoveLocal(), CStdNoGfx::RestoreDeviceObjects(), C4PlayerInfoList::RestoreSavegameInfos(), C4GameSave::Save(), C4GameSaveSavegame::SaveComponents(), C4Player::SetHostility(), C4MCParserErr::show(), C4Record::Start(), C4Playback::StreamToRecord(), C4Playback::Strip(), C4Player::Surrender(), C4PlayerList::SynchronizeLocalFiles(), C4Network2::Vote(), and C4PropListNumbered::~C4PropListNumbered().

Here is the call graph for this function:

◆ LogF()

bool LogF ( const char *  strMessage,
  ... 
)

Definition at line 262 of file C4Log.cpp.

263 {
264  va_list args; va_start(args, strMessage);
265  // Compose formatted message
266  StdStrBuf Buf;
267  Buf.FormatV(strMessage, args);
268  // Log
269  return Log(Buf.getData());
270 }

References StdStrBuf::FormatV(), StdStrBuf::getData(), and Log().

Referenced by C4Group::AccessEntry(), C4MusicFile::Announce(), C4Application::ApplyResolutionConstraints(), C4ControlJoinPlayer::C4ControlJoinPlayer(), CStdGL::CheckGLError(), C4Network2UPnPP::ClearNatMappings(), CompileFromBuf_Log(), CompileFromBuf_LogWarn(), C4ObjectList::CompileFunc(), C4Game::CompileRuntimeData(), CStdGL::CreateContext(), C4FoWAmbient::CreateFromLandscape(), CreatePath(), C4PlayerInfoList::CreateRestoreInfosForJoinedScriptPlayers(), C4Playback::DebugRecError(), DecompileToBuf_Log(), C4Value::Denumerate(), C4Application::DoInit(), C4DownloadDlg::DownloadFile(), CStdGL::Error(), C4GameControlNetwork::ExecQueuedSyncCtrl(), C4GameControlNetwork::ExecSyncControl(), C4Player::Execute(), C4Control::Execute(), C4GUI::ExpandHotkeyMarkup(), C4ComponentHost::FinishLoad(), C4Network2Res::GetStandalone(), C4ValueNumbers::GetValue(), C4TextureMap::Init(), C4SoundModifierList::Init(), C4AchievementGraphics::Init(), C4AbstractApp::Init(), C4Network2IO::Init(), C4Player::Init(), C4Player::InitControl(), C4Game::InitDefs(), C4FontLoader::InitFont(), C4MusicSystem::InitForScenario(), C4MusicSystem::InitializeMOD(), C4Game::InitMaterialTexture(), C4Game::InitNetworkFromReference(), C4Network2::Join(), C4PlayerList::Join(), C4Network2::LeagueNotifyDisconnect(), C4Network2::LeaguePlrAuth(), C4Network2::LeagueShowError(), C4Network2::LeagueUpdate(), C4Game::LinkScriptEngine(), C4AulDebug::Listen(), C4TextureShape::Load(), C4Surface::Load(), C4DefList::Load(), C4Config::Load(), C4KeyboardInput::LoadCustomConfig(), C4Extra::LoadDef(), C4MusicSystem::LoadDir(), C4GameResList::LoadFoldersWithLocalDefs(), C4PlayerInfo::LoadResource(), StdMeshSkeletonLoader::LoadSkeletonBinary(), C4TextureMap::LoadTextures(), C4PlayerInfoList::LocalJoinUnjoinedPlayersInQueue(), C4GUI::ComponentAligner::LogIt(), main(), C4Playback::Open(), C4Game::OpenScenario(), C4Value::operator==(), C4Network2Res::OptimizeStandalone(), C4Application::ParseCommandLine(), C4EditCursor::PerformDuplication(), C4MusicFileSDL::Play(), C4MusicSystem::Play(), C4Control::PreExecute(), C4MessageInput::ProcessCommand(), ProcessGroup(), Ogre::Mesh::Chunk::Read(), Ogre::Skeleton::Chunk::Read(), C4Playback::ReadBinary(), Ogre::Mesh::ChunkMesh::ReadImpl(), Ogre::Mesh::ChunkSubmesh::ReadImpl(), Ogre::Mesh::ChunkGeometry::ReadImpl(), Ogre::Skeleton::ChunkAnimation::ReadImpl(), C4PlayerInfoList::RecreatePlayerFiles(), C4PlayerInfoList::RecreatePlayers(), C4AulScriptEngine::ReLink(), C4Game::ReloadDef(), C4Game::ReloadParticle(), C4LSectors::Remove(), C4PlayerInfoList::RemoveUnassociatedPlayers(), C4LangStringTable::ReplaceStrings(), C4PlayerControlAssignment::ResolveRefs(), C4PlayerInfoList::RestoreSavegameInfos(), C4Network2::RetrieveRes(), C4Playback::ReWriteBinary(), C4Config::Save(), C4Player::Save(), C4ObjectInfo::Save(), C4GameSave::Save(), C4Game::SaveData(), C4GraphicsSystem::SaveScreenshot(), C4Player::ScenarioInit(), C4MusicSystem::ScheduleWaitTime(), C4Network2IOConnection::Send(), C4Network2ResChunk::Set(), C4Network2Res::SetByFile(), C4Object::SetOCF(), C4MusicSystem::SetPlayList(), C4Landscape::SetTextureIndex(), C4AbstractApp::SetVideoMode(), C4Playback::StreamToRecord(), C4Object::UpdateOCF(), and C4InVal::ValidateString().

Here is the call graph for this function:

◆ LogFatal()

bool LogFatal ( const char *  szMessage)

Definition at line 239 of file C4Log.cpp.

240 {
241  if (!szMessage) szMessage = "(null)";
242  // add to fatal error message stack - if not already in there (avoid duplication)
243  if (!SSearch(sFatalError.getData(), szMessage))
244  {
246  sFatalError.Append(szMessage);
247  }
248  // write to log - note that Log might overwrite a static buffer also used in szMessage
249  return !!Log(FormatString(LoadResStr("IDS_ERR_FATAL"), szMessage).getData());
250 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:369
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
bool isNull() const
Definition: StdBuf.h:441
void AppendChar(char cChar)
Definition: StdBuf.h:588
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

References StdStrBuf::Append(), StdStrBuf::AppendChar(), FormatString(), StdStrBuf::getData(), StdStrBuf::isNull(), LoadResStr(), Log(), sFatalError, and SSearch().

Referenced by C4Game::CheckObjectEnumeration(), C4Network2ResList::CreateNetworkFolder(), C4MaterialMap::CrossMapMaterials(), C4Application::DoInit(), C4GameControlNetwork::DoInput(), C4Startup::EnsureLoaded(), C4GameControl::Execute(), C4Network2::HandleJoinData(), C4Game::Init(), C4GraphicsResource::Init(), C4Network2IO::Init(), C4LandscapeRenderGL::Init(), C4LoaderScreen::Init(), C4Game::InitControl(), C4Game::InitDefs(), C4FontLoader::InitFont(), C4StartupGraphics::InitFonts(), C4Network2::InitHost(), C4Network2::InitLeague(), C4Game::InitMaterialTexture(), C4GameRes::InitNetwork(), C4Game::InitNetworkFromAddress(), C4Game::InitNetworkFromReference(), C4Game::InitNetworkHost(), C4Game::InitPlayerControlSettings(), C4Game::InitPlayers(), C4GameControl::InitReplay(), C4Game::InitScriptEngine(), C4Network2::LeagueStart(), C4AulDebug::Listen(), C4GameParameters::Load(), C4DefList::Load(), C4Game::LoadScenarioComponents(), C4Playback::Open(), C4Game::OpenScenario(), C4Application::PreInit(), C4Game::PreInit(), C4InteractiveThread::ProcessEvents(), C4GraphicsResource::RegisterGlobalGraphics(), C4GroupSet::RegisterParentFolders(), C4LandscapeRenderGL::ReInit(), C4PlayerControlAssignment::ResolveRefs(), and C4Network2::RetrieveRes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogSilent() [1/2]

bool LogSilent ( const char *  szMessage)

Definition at line 197 of file C4Log.cpp.

198 {
199  return LogSilent(szMessage, false);
200 }

References LogSilent().

Here is the call graph for this function:

◆ LogSilent() [2/2]

bool LogSilent ( const char *  szMessage,
bool  fConsole 
)

Definition at line 126 of file C4Log.cpp.

127 {
128  if (!Application.AssertMainThread()) return false;
129  // security
130  if (!szMessage) return false;
131 
132  // add timestamp
133  time_t timenow; time(&timenow);
134  StdStrBuf TimeMessage;
135  TimeMessage.SetLength(11 + SLen(szMessage) + 1);
136  strftime(TimeMessage.getMData(), 11 + 1, "[%H:%M:%S] ", localtime(&timenow));
137 
138  // output until all data is written
139  const char *pSrc = szMessage;
140  do
141  {
142  // timestamp will always be that length
143  char *pDest = TimeMessage.getMData() + 11;
144 
145  // copy rest of message, skip tags
146  C4Markup Markup(false);
147  while (*pSrc)
148  {
149  Markup.SkipTags(&pSrc);
150  // break on crlf
151  while (*pSrc == '\r') pSrc++;
152  if (*pSrc == '\n') { pSrc++; break; }
153  // copy otherwise
154  if (*pSrc) *pDest++ = *pSrc++;
155  }
156  *pDest++='\n'; *pDest = '\0';
157 
158  // Save into log file
159  if (C4LogFile)
160  {
161  fputs(TimeMessage.getData(),C4LogFile);
162  fflush(C4LogFile);
163  }
164 
165  // Save into record log file, if available
166  if(Control.GetRecord())
167  {
168  Control.GetRecord()->GetLogFile()->Write(TimeMessage.getData(), TimeMessage.getLength());
169  #ifdef IMMEDIATEREC
171  #endif
172  }
173 
174 
175  // Write to console
176  if (fConsole)
177  {
178 #if defined(_WIN32)
179  // debug: output to VC console when running with debugger
180  // Otherwise, print to stdout to allow capturing the log.
181  if (IsDebuggerPresent())
182  OutputDebugString(TimeMessage.GetWideChar());
183  else
184 #endif
185  {
186  fputs(TimeMessage.getData(),stdout);
187  fflush(stdout);
188  }
189  }
190 
191  }
192  while (*pSrc);
193 
194  return true;
195 }
C4GameControl Control
size_t SLen(const char *sptr)
Definition: Standard.h:74
C4Record * GetRecord()
CStdFile * GetLogFile()
Definition: C4Record.h:278
bool Write(const void *pBuffer, int iSize)
Definition: CStdFile.cpp:240
bool Flush()
Definition: CStdFile.h:70
void SetLength(size_t iLength)
Definition: StdBuf.h:509
size_t getLength() const
Definition: StdBuf.h:445

References Application, C4AbstractApp::AssertMainThread(), C4LogFile, Control, CStdFile::Flush(), StdStrBuf::getData(), StdStrBuf::getLength(), C4Record::GetLogFile(), StdStrBuf::getMData(), C4GameControl::GetRecord(), StdStrBuf::SetLength(), C4Markup::SkipTags(), SLen(), and CStdFile::Write().

Referenced by C4ObjectList::CheckSort(), DebugLog(), C4LSectors::Dump(), Log(), LogSilent(), LogSilentF(), C4GameLobby::MainDlg::OnMessage(), C4InteractiveThread::ProcessEvents(), C4MainStat::Show(), C4FoWLightSection::Update(), and CPNGFile::WaitForSaves().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogSilentF()

bool LogSilentF ( const char *  strMessage,
  ... 
)

Definition at line 272 of file C4Log.cpp.

273 {
274  va_list args; va_start(args, strMessage);
275  // Compose formatted message
276  StdStrBuf Buf;
277  Buf.FormatV(strMessage, args);
278  // Log
279  return LogSilent(Buf.getData());
280 }

References StdStrBuf::FormatV(), StdStrBuf::getData(), and LogSilent().

Referenced by C4FoWLightSection::CalculateTriangles(), C4Network2::ChangeGameStatus(), C4ConfigNetwork::CheckPortsForCollisions(), C4Network2Res::Clear(), C4GUI::ConfirmationDialog::ConfirmationDialog(), C4Network2IO::ConnectWithSocket(), CStdGL::CreateContext(), C4Network2Client::DoConnectAttempt(), C4Network2Client::DoTCPSimultaneousOpen(), C4Network2Res::GetStandalone(), C4Network2::HandleConn(), C4Network2::HandleConnRe(), C4Network2::HandleJoinData(), C4Network2::HandleStatus(), C4Network2IO::Init(), C4Network2::OnClientDisconnect(), C4Network2::OnConnect(), C4Network2::OnConnectFail(), C4Network2::OnDisconn(), C4Network2::OnDisconnect(), C4Network2::OnStatusAck(), C4Network2Res::SetByFile(), C4Network2Res::SetByGroup(), C4MainStat::Show(), C4GUI::Screen::ShowMessage(), C4GUI::Screen::ShowMessageModal(), C4MainStat::ShowPart(), C4Game::Synchronize(), and C4FoWLightSection::Update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenExtraLogs()

bool OpenExtraLogs ( )

Definition at line 83 of file C4Log.cpp.

84 {
85  // shader log in editor mode (only one file)
86  bool success = true;
87  if (C4Shader::IsLogging())
88  {
89 #ifdef _WIN32
90  C4ShaderLogFile = _fsopen(Config.AtUserDataPath(C4CFN_LogShader), "wt", _SH_DENYWR);
91 #elif defined(HAVE_SYS_FILE_H)
93  if (C4ShaderLogFile && flock(fileno(C4ShaderLogFile), LOCK_EX | LOCK_NB) != 0)
94  {
95  DebugLog("Couldn't lock shader log file, closing.");
96  fclose(C4ShaderLogFile);
97  C4ShaderLogFile = nullptr;
98  }
99 #else
101 #endif
102  if (!C4ShaderLogFile) success = false;
103  }
104  return success;
105 }
#define C4CFN_LogShader
Definition: C4Components.h:143
C4Config Config
Definition: C4Config.cpp:930
const char * AtUserDataPath(const char *filename)
Definition: C4Config.cpp:586
static bool IsLogging()
Definition: C4Shader.cpp:665

References C4Config::AtUserDataPath(), C4CFN_LogShader, C4ShaderLogFile, Config, DebugLog(), and C4Shader::IsLogging().

Referenced by C4Application::DoInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenLog()

bool OpenLog ( )

Definition at line 48 of file C4Log.cpp.

49 {
50  // open
51  sLogFileName = C4CFN_Log; int iLog = 2;
52 #ifdef _WIN32
53  while (!(C4LogFile = _fsopen(Config.AtUserDataPath(sLogFileName.getData()), "wt", _SH_DENYWR)))
54 #elif defined(HAVE_SYS_FILE_H)
55  int fd = 0;
56  while (!(fd = open(Config.AtUserDataPath(sLogFileName.getData()), O_WRONLY | O_CREAT, 0644)) || flock(fd, LOCK_EX|LOCK_NB))
57 #else
58  while (!(C4LogFile = fopen(Config.AtUserDataPath(sLogFileName.getData()), "wb")))
59 #endif
60  {
61  // Already locked by another instance?
62 #if !defined(_WIN32) && defined(HAVE_SYS_FILE_H)
63  if (fd) close(fd);
64 #else
65  if (C4LogFile) fclose(C4LogFile);
66 #endif
67  // If the file does not yet exist, the directory is r/o
68  // don't go on then, or we have an infinite loop
69  if (access(Config.AtUserDataPath(sLogFileName.getData()), 0))
70  return false;
71  // try different name
73  }
74 #if !defined(_WIN32) && defined(HAVE_SYS_FILE_H)
75  ftruncate(fd, 0);
76  C4LogFile = fdopen(fd, "wb");
77 #endif
78  // save start time
79  time(&C4LogStartTime);
80  return true;
81 }
#define C4CFN_LogEx
Definition: C4Components.h:142
#define C4CFN_Log
Definition: C4Components.h:141
time_t C4LogStartTime
Definition: C4Log.cpp:43
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174

References C4Config::AtUserDataPath(), C4CFN_Log, C4CFN_LogEx, C4LogFile, C4LogStartTime, Config, StdStrBuf::Format(), StdStrBuf::getData(), and sLogFileName.

Referenced by C4Application::DoInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetFatalError()

void ResetFatalError ( )

Definition at line 252 of file C4Log.cpp.

253 {
254  sFatalError.Clear();
255 }

References StdStrBuf::Clear(), and sFatalError.

Referenced by C4Startup::DoStartup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShaderLog()

bool ShaderLog ( const char *  szMessage)

Definition at line 343 of file C4Log.cpp.

344 {
345  // security
346  if (!C4ShaderLogFile) return false;
347  if (!Application.AssertMainThread()) return false;
348  if (!szMessage) return false;
349  // output into shader log file
350  fputs(szMessage, C4ShaderLogFile);
351  fputs("\n", C4ShaderLogFile);
352  fflush(C4ShaderLogFile);
353  return true;
354 }

References Application, C4AbstractApp::AssertMainThread(), and C4ShaderLogFile.

Referenced by C4Shader::Init(), and ShaderLogF().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShaderLogF()

bool ShaderLogF ( const char *  strMessage ...)

Definition at line 356 of file C4Log.cpp.

357 {
358  va_list args; va_start(args, strMessage);
359  StdStrBuf Buf;
360  Buf.FormatV(strMessage, args);
361  return ShaderLog(Buf.getData());
362 }
bool ShaderLog(const char *szMessage)
Definition: C4Log.cpp:343

References StdStrBuf::FormatV(), StdStrBuf::getData(), and ShaderLog().

Referenced by C4Shader::Init(), and C4Shader::Refresh().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ C4LogFile

FILE* C4LogFile =nullptr

Definition at line 41 of file C4Log.cpp.

Referenced by CloseLog(), GetLogFD(), LogSilent(), and OpenLog().

◆ C4LogStartTime

time_t C4LogStartTime

Definition at line 43 of file C4Log.cpp.

Referenced by OpenLog().

◆ C4ShaderLogFile

FILE* C4ShaderLogFile = nullptr

Definition at line 42 of file C4Log.cpp.

Referenced by CloseLog(), OpenExtraLogs(), and ShaderLog().

◆ iDisableLog

int iDisableLog = 0

Definition at line 202 of file C4Log.cpp.

Referenced by Log().

◆ sFatalError

StdStrBuf sFatalError

Definition at line 46 of file C4Log.cpp.

Referenced by GetFatalError(), LogFatal(), and ResetFatalError().

◆ sLogFileName

StdStrBuf sLogFileName

Definition at line 44 of file C4Log.cpp.

Referenced by GetLogPos(), GetLogSection(), and OpenLog().