1. -- 
  2. --  Copyright (c) 2008-2009, 
  3. --  Reto Buerki, Adrian-Ken Rueegsegger 
  4. --  secunet SwissIT AG 
  5. -- 
  6. --  This file is part of Alog. 
  7. -- 
  8. --  Alog is free software; you can redistribute it and/or modify 
  9. --  it under the terms of the GNU Lesser General Public License as published 
  10. --  by the Free Software Foundation; either version 2.1 of the License, or 
  11. --  (at your option) any later version. 
  12. -- 
  13. --  Alog is distributed in the hope that it will be useful, 
  14. --  but WITHOUT ANY WARRANTY; without even the implied warranty of 
  15. --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  16. --  GNU Lesser General Public License for more details. 
  17. -- 
  18. --  You should have received a copy of the GNU Lesser General Public License 
  19. --  along with Alog; if not, write to the Free Software 
  20. --  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 
  21. --  MA  02110-1301  USA 
  22. -- 
  23.  
  24. with Ada.Strings.Bounded; 
  25. with Ada.Strings.Unbounded; 
  26. with Ada.Command_Line; 
  27. with Ada.Calendar; 
  28.  
  29. with Alog.Log_Request; 
  30.  
  31. --  Alog facilities package. Provides common data and methods used by all 
  32. --  facilities. 
  33. package Alog.Facilities is 
  34.  
  35.    use Ada.Strings.Bounded; 
  36.    use Ada.Strings.Unbounded; 
  37.  
  38.    type Instance is abstract tagged limited private; 
  39.    --  Abstract type facility instance. All facilities in the Alog framework 
  40.    --  must implement this type. 
  41.  
  42.    subtype Class is Instance'Class; 
  43.  
  44.    type Handle is access all Class; 
  45.  
  46.    function "=" 
  47.      (Left  : Handle; 
  48.       Right : Handle) return Boolean; 
  49.    --  Equal function. 
  50.  
  51.    procedure Set_Name 
  52.      (Facility : in out Class; 
  53.       Name     :        String); 
  54.    --  Set facility name. 
  55.  
  56.    function Get_Name (Facility : Class) return String; 
  57.    --  Get facility name. 
  58.  
  59.    function Get_Timestamp 
  60.      (Facility : Class; 
  61.       Time     : Ada.Calendar.Time := Ada.Calendar.Clock) 
  62.       return String; 
  63.    --  Creates a timestamp and returns it as String. If no Time is given, the 
  64.    --  current time is used. 
  65.  
  66.    procedure Process 
  67.      (Facility : Class; 
  68.       Request  : Log_Request.Instance); 
  69.    --  Process a log request. 
  70.  
  71.    procedure Write 
  72.      (Facility : Instance; 
  73.       Level    : Log_Level := Info; 
  74.       Msg      : String) is abstract; 
  75.    --  Write message with specified log level. This procedure must be 
  76.    --  implemented by all facilities. 
  77.  
  78.    procedure Toggle_Write_Timestamp 
  79.      (Facility : in out Class; 
  80.       State    :        Boolean); 
  81.    --  Enable/disable whether a timestamp is written for log messages. 
  82.  
  83.    procedure Toggle_UTC_Timestamp 
  84.      (Facility : in out Class; 
  85.       State    :        Boolean); 
  86.    --  Enable/disable UTC timestamps for log messages. 
  87.  
  88.    function Is_Write_Timestamp (Facility : Class) return Boolean; 
  89.    --  Returns the current value of Write_Timestamp. 
  90.  
  91.    function Is_UTC_Timestamp (Facility : Class) return Boolean; 
  92.    --  Returns True if the timestamp of the facility is written in UTC time. 
  93.  
  94.    procedure Toggle_Write_Loglevel 
  95.      (Facility : in out Class; 
  96.       State    :        Boolean); 
  97.    --  Enable/disable whether the loglevel is written for log messages. 
  98.  
  99.    function Is_Write_Loglevel (Facility : Class) return Boolean; 
  100.    --  Returns the current value of Write_Loglevel. 
  101.  
  102.    procedure Toggle_Write_Source 
  103.      (Facility : in out Class; 
  104.       State    :        Boolean); 
  105.    --  Enable/disable whether the source of the message is logged. 
  106.  
  107.    function Is_Write_Source (Facility : Class) return Boolean; 
  108.    --  Returns True if writing of log message sources is enabled. 
  109.  
  110.    procedure Setup (Facility : in out Instance) is null; 
  111.    --  Each facility must provide a Setup-procedure. These procedures are called 
  112.    --  by Logger instances when attaching Facilities. All needed operations 
  113.    --  prior to writing log messages should be done here. 
  114.  
  115.    procedure Teardown (Facility : in out Instance) is null; 
  116.    --  Each facility must provide a Teardown-procedure. These procedures are 
  117.    --  called by Logger instances when detaching Facilities or when the logger 
  118.    --  object gets out of scope. 
  119.  
  120.    package BS_Path is new Generic_Bounded_Length (Max_Path_Length); 
  121.    use BS_Path; 
  122.    --  Bounded string with length Max_Path_Length. Used in methods which 
  123.    --  involve filesystem operations. 
  124.  
  125. private 
  126.  
  127.    type Instance is abstract tagged limited record 
  128.       Name             : Unbounded_String := 
  129.         To_Unbounded_String (Ada.Command_Line.Command_Name); 
  130.       --  Facility Name. Defaults to command-name (first argument). If multiple 
  131.       --  facilities are used, names must be set differently. 
  132.  
  133.       Timestamp_Format : String (1 .. 11) := "%b %d %Y %T"; 
  134.       --  Default timestamp format to use in this facility. 
  135.  
  136.       Write_Timestamp  : Boolean := True; 
  137.       --  If True, a timestamp is written with the log message. 
  138.  
  139.       UTC_Timestamp    : Boolean := False; 
  140.       --  If True, the timestamp is written in UTC time. 
  141.       --  (log message timestamps are written timezone-dependent). 
  142.  
  143.       Write_Loglevel   : Boolean := False; 
  144.       --  If True, the loglevel associated with the log message is written. 
  145.  
  146.       Write_Source     : Boolean := True; 
  147.       --  If True, the source of a log message is prepended to the message. 
  148.    end record; 
  149.  
  150. end Alog.Facilities;