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