Skip to content

Commit

Permalink
M agpl-trace-file.adb
Browse files Browse the repository at this point in the history
M    agpl-trace-utils.adb
M    agpl-trace-utils.ads
M    agpl-trace-root.adb
M    agpl-trace-root.ads
M    agpl-trace-console.adb
M    agpl-trace.adb
M    agpl-trace.ads
  • Loading branch information
mosteo committed Jul 24, 2006
1 parent 85ee436 commit ba0edf9
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 17 deletions.
5 changes: 1 addition & 4 deletions agpl-trace-console.adb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ package body Agpl.Trace.Console is
Section : in String := "")
is
begin
if This.Must_Log (Level, Section) then
Agpl.Text_Io.Put_Line (This.Decorate (Text, Level, Section));
Root.Object (This).Log (Text, Level, Section);
end if;
Agpl.Text_Io.Put_Line (This.Decorate (Text, Level, Section));
end Log;

end Agpl.Trace.Console;
14 changes: 5 additions & 9 deletions agpl-trace-file.adb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ package body Agpl.Trace.File is
Section : in String := "")
is
begin
if This.Must_Log (Level, Section) then
if not This.Opened then
Set_File (This);
pragma Assert (This.Opened);
end if;

Put_Line (This.File, This.Decorate (Text, Level, Section));
Flush (This.File);
if not This.Opened then
Set_File (This);
pragma Assert (This.Opened);
end if;

Root.Object (This).Log (Text, Level, Section);
Put_Line (This.File, This.Decorate (Text, Level, Section));
Flush (This.File);
end Log;

--------------
Expand Down
2 changes: 1 addition & 1 deletion agpl-trace-root.adb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ package body Agpl.Trace.Root is
return
This.Active and then
Level >= This.Level and then
(Level >= Error or else
(Level >= Warning or else
Section = "" or else
This.Sections.Contains (Section));
end Must_Log;
Expand Down
4 changes: 3 additions & 1 deletion agpl-trace-root.ads
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ package Agpl.Trace.Root is
Text : in String;
Level : in Levels;
Section : in String := "") is null;
-- No need for implementations of this object to call Must_Log, it's called
-- in the Agpl.Trace.Log subprogram.

not overriding
overriding
function Must_Log (This : in Object;
Level : in Levels;
Section : in String) return Boolean;
Expand Down
27 changes: 27 additions & 0 deletions agpl-trace-utils.adb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
with Agpl.Calendar.Format;
with Agpl.Strings;

package body Agpl.Trace.Utils is

Expand Down Expand Up @@ -59,4 +60,30 @@ package body Agpl.Trace.Utils is
"[" &Calendar.Format.Timestamp & "] " & Text;
end Prepend_Level_Timestamp;

-------------------------------------
-- Prepend_Level_Timestamp_Section --
-------------------------------------

function Prepend_Level_Timestamp_Section (Text : in String;
Level : in Levels;
Section : in String) return String
is
Section_Width : constant := 16;
use Strings;
begin
if Section'Length <= Section_Width then
return
Prefix (Level) &
"[" & Calendar.Format.Timestamp & "]" &
"[" & Lpad (Section, Section_Width) & "] " &
Text;
else
return
Prefix (Level) &
"[" & Calendar.Format.Timestamp & "]" &
"[.." & Section (Section'Last - Section_Width + 3 ..Section'Last) & "] " &
Text;
end if;
end Prepend_Level_Timestamp_Section;

end Agpl.Trace.Utils;
5 changes: 5 additions & 0 deletions agpl-trace-utils.ads
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ package Agpl.Trace.Utils is
-- Add level & timestamp
pragma Inline (Prepend_Level_Timestamp);

function Prepend_Level_Timestamp_Section (Text : in String;
Level : in Levels;
Section : in String) return String;
pragma Inline (Prepend_Level_Timestamp_Section);

end Agpl.Trace.Utils;
6 changes: 4 additions & 2 deletions agpl-trace.adb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ package body Agpl.Trace is
Section : in String := "") is
begin
if Enabled then
if This /= null then
if This /= null and then This.Must_Log (Level, Section) then
Safe.Log (This.all, Text, Level, Section);
end if;
end if;
Expand All @@ -143,7 +143,9 @@ package body Agpl.Trace is
end if;

for I in Tracers.First_Index .. Tracers.Last_Index loop
Safe.Log (Tracers.Element (I).all, Text, Level, Section);
if Tracers.Element (I).Must_Log (Level, Section) then
Safe.Log (Tracers.Element (I).all, Text, Level, Section);
end if;
end loop;
end if;
end Log;
Expand Down
5 changes: 5 additions & 0 deletions agpl-trace.ads
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ package Agpl.Trace is
is abstract;
-- Apply the decorator.

function Must_Log (This : in Object;
Level : in Levels;
Section : in String) return Boolean
is abstract;

procedure Log
(Text : in String;
Level : in Levels;
Expand Down

0 comments on commit ba0edf9

Please sign in to comment.