瀏覽代碼

Optimizing application logging macros

Source commit: 2e21f71128580788ce1881e044a93d63e801d719
Martin Prikryl 3 年之前
父節點
當前提交
9b0856ca7a
共有 3 個文件被更改,包括 7 次插入2 次删除
  1. 2 2
      source/core/CoreMain.h
  2. 3 0
      source/core/SessionInfo.cpp
  3. 2 0
      source/core/SessionInfo.h

+ 2 - 2
source/core/CoreMain.h

@@ -11,8 +11,8 @@ extern TStoredSessionList *StoredSessions;
 extern bool AnySession;
 class TApplicationLog;
 extern TApplicationLog * ApplicationLog;
-#define AppLog(S) ApplicationLog->Log(S)
-#define AppLogFmt(S, F) ApplicationLog->Log(Format(S, ARRAYOFCONST(F)))
+#define AppLog(S) if (ApplicationLog->Logging) ApplicationLog->Log(S)
+#define AppLogFmt(S, F) AppLog(FORMAT(S, F))
 //---------------------------------------------------------------------------
 void CoreInitialize();
 void CoreFinalize();

+ 3 - 0
source/core/SessionInfo.cpp

@@ -1762,6 +1762,7 @@ void __fastcall TActionLog::SetEnabled(bool value)
 TApplicationLog::TApplicationLog()
 {
   FFile = NULL;
+  FLogging = false;
   FCriticalSection.reset(new TCriticalSection());
 }
 //---------------------------------------------------------------------------
@@ -1773,12 +1774,14 @@ TApplicationLog::~TApplicationLog()
     fclose(static_cast<FILE *>(FFile));
     FFile = NULL;
   }
+  FLogging = false;
 }
 //---------------------------------------------------------------------------
 void TApplicationLog::Enable(const UnicodeString & Path)
 {
   UnicodeString Dummy;
   FFile = OpenFile(Path, Now(), NULL, false, Dummy);
+  FLogging = true;
 }
 //---------------------------------------------------------------------------
 void TApplicationLog::AddStartupInfo()

+ 2 - 0
source/core/SessionInfo.h

@@ -366,9 +366,11 @@ public:
   void Enable(const UnicodeString & Path);
   void AddStartupInfo();
   void __fastcall Log(const UnicodeString & S);
+  __property bool Logging = { read = FLogging };
 
 private:
   void * FFile;
+  bool FLogging;
   std::unique_ptr<TCriticalSection> FCriticalSection;
 };
 //---------------------------------------------------------------------------