From fffe085266382cfcaeed4b600f4d6bb104bfa38d Mon Sep 17 00:00:00 2001 From: tobigun Date: Fri, 2 May 2008 16:43:05 +0000 Subject: - replaced some DebugWriteln() with Log.Log...() - added LogFileLevel to be able to control which log-messages are written to the log-file (Error.log) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1053 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index d2664b1e..ca488e7e 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -35,8 +35,10 @@ const LOG_LEVEL_CRITICAL_MAX = LOG_LEVEL_ERROR-1; LOG_LEVEL_CRITICAL = 0; LOG_LEVEL_NONE = -1; - - LOG_LEVEL_DEFAULT = LOG_LEVEL_ERROR; + + // define level that Log(File)Level is initialized with + LOG_LEVEL_DEFAULT = LOG_LEVEL_INFO; + LOG_FILE_LEVEL_DEFAULT = LOG_LEVEL_ERROR; type TLog = class @@ -47,6 +49,8 @@ type BenchmarkFileOpened: boolean; LogLevel: integer; + // level of messages written to the log-file + LogFileLevel: integer; procedure LogToFile(const Text: string); public @@ -125,6 +129,7 @@ end; constructor TLog.Create; begin LogLevel := LOG_LEVEL_DEFAULT; + LogFileLevel := LOG_FILE_LEVEL_DEFAULT; FileOutputEnabled := true; end; @@ -279,6 +284,8 @@ procedure TLog.LogMsg(const Text: string; Level: integer); var LogMsg: string; begin + // TODO: what if (LogFileLevel < LogLevel)? Log to file without printing to + // console or do not log at all? At the moment nothing is logged. if (Level <= LogLevel) then begin if (Level <= LOG_LEVEL_CRITICAL_MAX) then @@ -295,24 +302,25 @@ begin LogMsg := 'DEBUG: ' + Text; // output log-message - DebugWriteLn(LogMsg); - - // actions for error- and more severe levels - if (Level <= LOG_LEVEL_ERROR_MAX) then + if (Level <= LogLevel) then begin - // Write message to log-file - LogToFile(Text); + DebugWriteLn(LogMsg); end; - - // actions for critical- and more severe levels - if (Level <= LOG_LEVEL_CRITICAL_MAX) then + + // write message to log-file + if (Level <= LogFileLevel) then begin - // Show information (window) - ShowMessage(Text, mtError); - // Exit Application - Halt; + LogToFile(LogMsg); end; end; + + // exit application on criticial errors (cannot be turned off) + if (Level <= LOG_LEVEL_CRITICAL_MAX) then + begin + // Show information (window) + ShowMessage(Text, mtError); + Halt; + end; end; procedure TLog.LogMsg(const Msg, Context: string; Level: integer); -- cgit v1.2.3