1. -- 
  2. --  Copyright (c) 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.Exceptions; 
  25. with Ada.Task_Identification; 
  26.  
  27. with Alog.Facilities; 
  28. with Alog.Transforms; 
  29.  
  30. --  Tasked Logger instance. Facilities can be attached to this logger instance 
  31. --  in order to log to different targets simultaneously. This instance provides 
  32. --  task-safe concurrent logging. 
  33. package Alog.Tasked_Logger is 
  34.  
  35.    type Facility_Update_Handle is 
  36.    not null access procedure (Facility_Handle : Facilities.Handle); 
  37.    --  Handle to facility update procedure. 
  38.  
  39.    task type Instance (Init : Boolean := False) is 
  40.  
  41.       entry Attach_Facility (Facility : Facilities.Handle); 
  42.       --  Attach a facility to tasked logger instance. 
  43.  
  44.       entry Attach_Default_Facility; 
  45.       --  Attach default facility to tasked logger instance. 
  46.  
  47.       entry Detach_Facility (Name : String); 
  48.       --  Detach a facility from tasked logger instance. 
  49.  
  50.       entry Detach_Default_Facility; 
  51.       --  Detach default facility from tasked logger instance. 
  52.  
  53.       entry Facility_Count (Count : out Natural); 
  54.       --  Return number of attached facilites. 
  55.  
  56.       entry Update 
  57.         (Name    : String; 
  58.          Process : Facility_Update_Handle); 
  59.       --  Update a specific facility identified by 'Name'. Call the 'Process' 
  60.       --  procedure to perform the update operation. Clear the last exception 
  61.       --  occurrence for the caller if none occurred or replace existing 
  62.       --  occurrence with new raised exception. 
  63.  
  64.       entry Iterate (Process : Facility_Update_Handle); 
  65.       --  Call 'Process' for all attached facilities. 
  66.  
  67.       entry Attach_Transform (Transform : Transforms.Handle); 
  68.       --  Attach a transform to tasked logger instance. 
  69.  
  70.       entry Detach_Transform (Name : String); 
  71.       --  Detach a transform from tasked logger instance. 
  72.  
  73.       entry Transform_Count (Count : out Natural); 
  74.       --  Return number of attached transforms. 
  75.  
  76.       entry Log_Message 
  77.         (Source : String := ""; 
  78.          Level  : Log_Level; 
  79.          Msg    : String; 
  80.          Caller : Ada.Task_Identification.Task_Id := 
  81.            Ada.Task_Identification.Null_Task_Id); 
  82.       --  Log a message. The Write_Message() procedure of all attached 
  83.       --  facilities is called. Depending on the Log-Threshold set, the message 
  84.       --  is logged to different targets (depending on the facilites) 
  85.       --  automatically. Clear the last exception occurrence for the caller if 
  86.       --  none occurred or replace existing occurrence with new raised 
  87.       --  exception. 
  88.       --  If caller is not specified the executing task's ID is used instead. 
  89.       --  Since Log_Message'Caller can not be used as default parameter the 
  90.       --  entry checks if the variable is set to 'Null_Task_Id' in the body. 
  91.       -- 
  92.       --  Prior to actually processing the given log message the policy database 
  93.       --  is inquired if the log message with given source and level should be 
  94.       --  logged. 
  95.  
  96.       entry Clear; 
  97.       --  Clear tasked logger instance. Detach and teardown all attached 
  98.       --  facilities and transforms and clear any stored exceptions. 
  99.  
  100.       entry Get_Last_Exception 
  101.         (Occurrence : out Ada.Exceptions.Exception_Occurrence; 
  102.          Caller     :     Ada.Task_Identification.Task_Id := 
  103.            Ada.Task_Identification.Null_Task_Id); 
  104.       --  Return last known Exception_Occurrence. If no exception occured return 
  105.       --  Null_Occurrence. 
  106.       --  If caller is not specified the executing task's ID is used instead. 
  107.       --  Since Get_Last_Exception'Caller can not be used as default parameter 
  108.       --  the entry checks if the variable is set to 'Null_Task_Id' in the body. 
  109.  
  110.       entry Shutdown; 
  111.       --  Explicitly shutdown tasked logger. 
  112.  
  113.    end Instance; 
  114.    --  Tasked logger instance. The Init discriminant defines whether or not a 
  115.    --  default 'stdout' (FD facility without logfile set) is attached 
  116.    --  automatically. Default is 'False'. Set Init to 'True' if you want to make 
  117.    --  sure minimal stdout logging is possible as soon as a new logger is 
  118.    --  instantiated. 
  119.  
  120.    type Handle is access all Instance; 
  121.    --  Handle to tasked logger type. 
  122.  
  123. end Alog.Tasked_Logger;