Skip to content

Commit

Permalink
feat: Log ERR
Browse files Browse the repository at this point in the history
  • Loading branch information
gcarreno committed Dec 9, 2024
1 parent b96ef44 commit 6720abf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/bot/irclogbot.bot.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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.');
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion src/common/irclogbot.common.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/database/irclogbot.database.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6720abf

Please sign in to comment.