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 APQ.PostgreSQL.Client; 
  25.  
  26. --  PGSQL facility. Used to log to a Postgresql database. 
  27. package Alog.Facilities.Pgsql is 
  28.  
  29.    type Instance is new Alog.Facilities.Instance with private; 
  30.    --  PGSQL logging facility. 
  31.  
  32.    type Handle is access all Instance; 
  33.  
  34.    overriding 
  35.    procedure Setup (Facility : in out Instance); 
  36.    --  Implementation of Setup-procedure. 
  37.  
  38.    overriding 
  39.    procedure Teardown (Facility : in out Instance); 
  40.    --  Implementation of Teardown-procedure. 
  41.  
  42.    procedure Set_Host_Name (Facility : in out Instance; Hostname : String); 
  43.    --  Set hostname of database server. 
  44.  
  45.    function Get_Host_Name (Facility : Instance) return String; 
  46.    --  Get hostname of database server. 
  47.  
  48.    procedure Set_Host_Address (Facility : in out Instance; Address : String); 
  49.    --  Set ip address of database server. 
  50.  
  51.    procedure Set_Host_Port (Facility : in out Instance; Port : Natural); 
  52.    --  Set port of database server. 
  53.  
  54.    function Get_Host_Port (Facility : Instance) return Natural; 
  55.    --  Get port of database server. 
  56.  
  57.    procedure Set_SQL_Trace 
  58.      (Facility : in out Instance; 
  59.       Filename :        String; 
  60.       Mode     :        APQ.Trace_Mode_Type); 
  61.    --  Set SQL trace parameters. 
  62.  
  63.    procedure Toggle_SQL_Trace 
  64.      (Facility : in out Instance; 
  65.       State    :        Boolean); 
  66.    --  Toggles tracing of SQL statements. 
  67.  
  68.    function Is_SQL_Trace (Facility : Instance) return Boolean; 
  69.    --  Tells whether sql tracing is enabled. 
  70.  
  71.    procedure Set_DB_Name (Facility : in out Instance; DB_Name : String); 
  72.    --  Set name of database. 
  73.  
  74.    function Get_DB_Name (Facility : Instance) return String; 
  75.    --  Get name of database. 
  76.  
  77.    procedure Set_Table_Name (Facility : in out Instance; Table_Name : String); 
  78.    --  Set name of database table. 
  79.  
  80.    function Get_Table_Name (Facility : Instance) return String; 
  81.    --  Get name of database table. 
  82.  
  83.    procedure Set_Level_Column_Name 
  84.      (Facility    : in out Instance; 
  85.       Column_Name : String); 
  86.    --  Set name of log level column. 
  87.  
  88.    function Get_Level_Column_Name (Facility : Instance) return String; 
  89.    --  Get name of log level column. 
  90.  
  91.    procedure Set_Timestamp_Column_Name 
  92.      (Facility    : in out Instance; 
  93.       Column_Name : String); 
  94.    --  Set name of log level column. 
  95.  
  96.    function Get_Timestamp_Column_Name (Facility : Instance) return String; 
  97.    --  Get name of timestamp column. 
  98.  
  99.    procedure Set_Message_Column_Name 
  100.      (Facility    : in out Instance; 
  101.       Column_Name : String); 
  102.    --  Set name of log message column. 
  103.  
  104.    function Get_Message_Column_Name (Facility : Instance) return String; 
  105.    --  Get name of log message column. 
  106.  
  107.    procedure Set_Credentials 
  108.      (Facility : in out Instance; 
  109.       Username :        String; 
  110.       Password :        String); 
  111.    --  Set credentials for the database connection. 
  112.  
  113.    function Get_Credentials (Facility : Instance) return String; 
  114.    --  Get credentials of database connection. Only the username is returned. 
  115.  
  116.    procedure Close_Connection (Facility : in out Instance); 
  117.    --  Close open database connection. 
  118.  
  119. private 
  120.  
  121.    overriding 
  122.    procedure Write 
  123.      (Facility : Instance; 
  124.       Level    : Log_Level := Info; 
  125.       Msg      : String); 
  126.    --  Implementation of the Write procedure for PGSQL. 
  127.  
  128.    type Log_SQL_Table is tagged record 
  129.       Name             : Unbounded_String := To_Unbounded_String ("alog"); 
  130.       Level_Column     : Unbounded_String := To_Unbounded_String ("level"); 
  131.       Timestamp_Column : Unbounded_String := To_Unbounded_String ("timestamp"); 
  132.       Message_Column   : Unbounded_String := To_Unbounded_String ("message"); 
  133.    end record; 
  134.    --  Holds Table/Column name information. 
  135.  
  136.    type Instance is new Alog.Facilities.Instance with record 
  137.       Log_Connection   : APQ.PostgreSQL.Client.Connection_Type; 
  138.       --  Database connection used for logging. 
  139.  
  140.       Trace_Filename   : Unbounded_String := 
  141.         To_Unbounded_String ("./trace.sql"); 
  142.       Trace_Mode       :  APQ.Trace_Mode_Type := APQ.Trace_APQ; 
  143.       --  SQL trace parameters 
  144.  
  145.       Log_Table        : Log_SQL_Table; 
  146.       --  Table to insert messages 
  147.    end record; 
  148.  
  149. end Alog.Facilities.Pgsql;