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