rxada_0.1.1_dd9da799/src/priv/rx-debug.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
with Ada.Exceptions;
with Ada.Tags;

with GNAT.IO;
with GNAT.Source_Info;

private with Ada.Strings;
private with Ada.Strings.Fixed;

package Rx.Debug is

   pragma Preelaborate;

   type Levels is (Impl, -- Implementation detail, for debugging
                   Note, -- Highly chatty
                   Info, -- Out-of-usual
                   Warn, -- Shouldn't happen but not critical (?)
                   Error  -- Something is definitely not working as expected
                   );

   Level : constant Levels := Info;
   --  Minimum level a message has to have for it to be printed

   Serialize_Trace : constant Boolean := True;
   --  This introduces a protected call, so use only for debugging purposes!

   procedure Log (S : String; Level : Levels); -- Prints S if above configured level

   procedure Trace (S : String; Prefix : String := GNAT.Source_Info.Source_Location);
   --  Log at Impl level

   procedure Trace (E       : Ada.Exceptions.Exception_Occurrence;
                    Msg     : String);

   procedure Put_Line (I : Rx_Integer);
   procedure Put_Line (S : String) renames Gnat.IO.Put_Line;

   function Trim (S : String) return String;

   function Image (I : Rx_Integer) return String is (Rx_Integer'Image (I));
   function Image (T : Ada.Tags.Tag) return String renames Ada.Tags.Expanded_Name;

   procedure Print (E : Ada.Exceptions.Exception_Occurrence);

   procedure Report (E       : Ada.Exceptions.Exception_Occurrence;
                     Msg     : String;
                     Level   : Levels := Error;
                     Reraise : Boolean := False);
   --  Prints Msg at level Level, prints the exception and optionally re-raises

   --  Early termination
   procedure Bailout (Exit_Code : Integer := 0);

private

   function Trim (S : String) return String is (Ada.Strings.Fixed.Trim (S, Ada.Strings.Both));

end Rx.Debug;