From 6720abf6c35759f586404eb8808f108d256b8383 Mon Sep 17 00:00:00 2001 From: Gustavo Carreno Date: Mon, 9 Dec 2024 15:59:14 +0000 Subject: [PATCH] feat: Log ERR --- src/bot/irclogbot.bot.pas | 9 +++++---- src/common/irclogbot.common.pas | 17 ++++++++++++++++- src/database/irclogbot.database.pas | 8 ++++---- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/bot/irclogbot.bot.pas b/src/bot/irclogbot.bot.pas index 7a46f2f..a00550e 100644 --- a/src/bot/irclogbot.bot.pas +++ b/src/bot/irclogbot.bot.pas @@ -165,6 +165,7 @@ procedure TIRCLogBot.OnPrivateMessage(ASender: TIdContext; const ANickname, except on e:Exception do begin + error('Replay error: %s', [e.Message]); FIRC.Say(ANickname, 'Something went wrong: "' + e.Message + '". It''s been logged. Please contact the admin if I stop working.'); end; end; @@ -252,7 +253,7 @@ procedure TIRCLogBot.Run; except on e:Exception do begin - debug('Error connecting: "%s".', [e.Message]); + error('Error connecting: "%s".', [e.Message]); end; end; try @@ -261,7 +262,7 @@ procedure TIRCLogBot.Run; except on e:Exception do begin - debug('Error joining: "%s".', [e.Message]); + error('Error joining: "%s".', [e.Message]); end; end; debug('Starting Replay Thread.'); @@ -283,7 +284,7 @@ procedure TIRCLogBot.Shutdown; except on e:Exception do begin - debug('Error disconnecting: "%s".', [e.Message]); + error('Error disconnecting: "%s".', [e.Message]); end; end; end; @@ -316,7 +317,7 @@ constructor TIRCLogBot.Create(const AConfig: TBotConfig); except on e:Exception do begin - debug('Error creating db: "%s".', [e.Message]); + error('Error creating db: "%s".', [e.Message]); end; end; end; diff --git a/src/common/irclogbot.common.pas b/src/common/irclogbot.common.pas index 82c25cd..0ecd274 100644 --- a/src/common/irclogbot.common.pas +++ b/src/common/irclogbot.common.pas @@ -17,13 +17,15 @@ interface procedure info(const AMessage: String); overload; procedure info(const AFormat: String; AValues: array of const);overload; +procedure error(const AMessage: String); overload; +procedure error(const AFormat: String; AValues: array of const);overload; procedure debug(const AMessage: String); overload; procedure debug(const AFormat: String; AValues: array of const);overload; implementation type - TLogLevel = (llInfo, llDebug); + TLogLevel = (llInfo, llError, llDebug); var dateTimeStr: String; @@ -35,6 +37,9 @@ procedure log(const ALevel: TLogLevel; const AMessage: String); llInfo:begin WriteLn(dateTimeStr, '[INF]: ', AMessage); end; + llError:begin + WriteLn(dateTimeStr, '[ERR]: ', AMessage); + end; llDebug:begin WriteLn(dateTimeStr, '[DBG]: ', AMessage); end; @@ -52,6 +57,16 @@ procedure info(const AFormat: String; AValues: array of const); Log(llInfo, Format(AFormat, AValues)); end; +procedure error(const AMessage: String); +begin + Log(llError, AMessage); +end; + +procedure error(const AFormat: String; AValues: array of const); +begin + Log(llError, Format(AFormat, AValues)); +end; + procedure debug(const AMessage: String); begin if DebugOn then diff --git a/src/database/irclogbot.database.pas b/src/database/irclogbot.database.pas index 85ebfe3..5ade1fe 100644 --- a/src/database/irclogbot.database.pas +++ b/src/database/irclogbot.database.pas @@ -56,7 +56,7 @@ procedure TDatabase.SetupTables; on e:Exception do begin FTransaction.Rollback; - debug('Error setting tables: "%s".', [e.Message]); + error('Error setting tables: "%s".', [e.Message]); end; end; end; @@ -81,7 +81,7 @@ procedure TDatabase.Insert(const ANickName, AChannel, AMessage: String); on e:Exception do begin FTransaction.Rollback; - debug('Error inserting message: "%s".', [e.Message]); + error('Error inserting message: "%s".', [e.Message]); end; end; finally @@ -137,7 +137,7 @@ function TDatabase.Get(const ACount: Integer): TStringList; on e:Exception do begin FTransaction.Rollback; - debug('Error retrieving lines: "%s".', [e.Message]); + error('Error retrieving lines: "%s".', [e.Message]); end; end; finally @@ -197,7 +197,7 @@ function TDatabase.Search(const AQuery: String): TStringList; on e:Exception do begin FTransaction.Rollback; - debug('Error retrieving lines: "%s".', [e.Message]); + error('Error retrieving lines: "%s".', [e.Message]); end; end; finally