Rombobjörn

summaryrefslogtreecommitdiff
path: root/system_log.ads
blob: 002218d98b2c83d8c22a50f0fa9a97dc5df7bd83 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
-- System_Log, a binding to the Unix syslog functions
-- Copyright 2009 B. Persson, Bjorn@Rombobeorn.se
--
-- This library is free software: you can redistribute it and/or modify it
-- under the terms of the GNU General Public License version 3, as published
-- by the Free Software Foundation.


package System_Log is

   -- System_Log is a binding to the Unix syslog functions. The logging
   -- functionality is common to all tasks. This binding is tasking-safe if the
   -- underlying C library is, except as noted below for Open_Log and Close_Log.

   type Log_Facility is
      (Kernel,    -- kernel messages
       User,      -- random user-level messages
       Mail,      -- mail system
       Daemon,    -- system daemons
       Syslog,    -- messages generated internally by syslogd
       LPR,       -- line printer subsystem
       News,      -- network news subsystem
       UUCP,      -- UUCP subsystem
       Cron,      -- clock daemon
       Authpriv,  -- security/authorization messages (private)
       FTP,       -- ftp daemon
       Local0,    -- reserved for local use
       Local1,    -- reserved for local use
       Local2,    -- reserved for local use
       Local3,    -- reserved for local use
       Local4,    -- reserved for local use
       Local5,    -- reserved for local use
       Local6,    -- reserved for local use
       Local7);   -- reserved for local use

   type Log_Level is
      (Emergency, -- system is unusable
       Alert,     -- action must be taken immediately
       Critical,  -- critical conditions
       Error,     -- error conditions
       Warning,   -- warning conditions
       Notice,    -- normal but significant condition
       Info,      -- informational
       Debug);    -- debug-level messages

   type Log_Levels is array(Log_Level) of Boolean;
   for Log_Levels'Size use 8;
   pragma Pack(Log_Levels);

   procedure Open_Log(Source_Name        : in String;
                      Facility           : in Log_Facility;
                      Console_On_Error   : in Boolean := False;
                      Delay_Open         : in Boolean := True;
                      Standard_Error_Too : in Boolean := False;
                      Include_PID        : in Boolean := False);
   -- Open_Log is used to specify how logging shall be done. It will connect to
   -- the system logger if Delay_Open is false. Calling Open_Log is optional.
   -- The connection to the system logger will be opened if necessary when Log
   -- is called.
   -- Open_Log will normally only be called once. If it must be called again,
   -- Close_Log should be called in between to avoid leaking memory.

   procedure Set_Log_Levels(New_Levels : in  Log_Levels);
   procedure Set_Log_Levels(New_Levels : in  Log_Levels;
                            Old_Levels : out Log_Levels);
   -- Set_Log_Levels activates those log levels that are true in New_Levels and
   -- deactivates those that are false. The second form reports in Old_Levels
   -- which log levels were active before the call.

   procedure Set_Log_Threshold(Threshold : in Log_Level);
   -- Set_Log_Threshold activates the log levels from Emergency to Threshold,
   -- inclusive, and deactivates the rest.

   procedure Log(Level : in Log_Level; Message : in String);
   -- Sends the message Message to the system logger if the log level Level is
   -- active, using the facility that was passed to Open_Log.

   procedure Log(Facility : in Log_Facility;
                 Level    : in Log_Level;
                 Message  : in String);
   -- Sends the message Message to the system logger if the log level Level is
   -- active, using the facility Facility.

   procedure Close_Log;
   -- Close_Log closes the connection to the system logger. Calling Close_Log
   -- before terminating is optional. In a multitasked program, Close_Log should
   -- not be called from multiple tasks simultaneously.

end System_Log;