File: policy_example1.adb

package info (click to toggle)
libalog 0.6.2-7.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 784 kB
  • sloc: ada: 4,353; makefile: 99; sh: 18; ansic: 5
file content (42 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (3)
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
with Alog.Dst_Filter;
with Alog.Logger;
with Alog.Facilities.File_Descriptor;

use Alog;

--  Alog destination loglevel policy example.
procedure Policy_Example1 is
   Log : Logger.Instance (Init => True);

   Facility_Name : constant String := "Application_Errors";
   Errors        : constant Facilities.File_Descriptor.Handle
     := new Facilities.File_Descriptor.Instance;
begin
   --  Write all error messages to '/tmp/errors.log'.
   Errors.Set_Logfile (Path => "/tmp/errors.log");
   Errors.Set_Name (Name => Facility_Name);
   Errors.Toggle_Write_Loglevel (State => True);

   --  Set loglevel policy to 'Error' for destination 'Application_Errors'.
   Dst_Filter.Set_Loglevel (Name  => Facility_Name,
                            Level => Error);

   Log.Attach_Facility (Facility => Facilities.Handle (Errors));

   --  This message will appear on stdout, but not in the error logfile.
   Log.Log_Message (Level  => Info,
                    Msg    => "This is not an error");
   --  This message will also be written to the error logfile.
   Log.Log_Message (Level  => Error,
                    Msg    => "This is an error");

   --  Set global loglevel to only log messages with level higher than Warning
   --  if no facility-specific level is set.
   Dst_Filter.Set_Default_Level (Level => Warning);
   --  This message will be filtered out.
   Log.Log_Message (Level  => Info,
                    Msg    => "This message will be filtered");
   --  This message will appear on stdout, but not in the error logfile.
   Log.Log_Message (Level  => Warning,
                    Msg    => "This is a warning message");
end Policy_Example1;