This file is indexed.

/usr/share/ada/adainclude/alog/alog-facilities-pgsql.adb is in libalog0.4.1-base-dev 0.4.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
--
--  Copyright (c) 2008-2009,
--  Reto Buerki, Adrian-Ken Rueegsegger
--
--  This file is part of Alog.
--
--  Alog is free software; you can redistribute it and/or modify
--  it under the terms of the GNU Lesser General Public License as published
--  by the Free Software Foundation; either version 2.1 of the License, or
--  (at your option) any later version.
--
--  Alog is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU Lesser General Public License for more details.
--
--  You should have received a copy of the GNU Lesser General Public License
--  along with Alog; if not, write to the Free Software
--  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
--  MA  02110-1301  USA
--

package body Alog.Facilities.Pgsql is

   -------------------------------------------------------------------------

   procedure Close_Connection (Facility : in out Instance) is
   begin
      Facility.Log_Connection.Reset;
   end Close_Connection;

   -------------------------------------------------------------------------

   function Get_Credentials (Facility : Instance) return String is
   begin
      return Facility.Log_Connection.User;
   end Get_Credentials;

   -------------------------------------------------------------------------

   function Get_DB_Name (Facility : Instance) return String is
   begin
      return Facility.Log_Connection.DB_Name;
   end Get_DB_Name;

   -------------------------------------------------------------------------

   function Get_Host_Name (Facility : Instance) return String is
   begin
      return Facility.Log_Connection.Host_Name;
   end Get_Host_Name;

   -------------------------------------------------------------------------

   function Get_Host_Port (Facility : Instance) return Natural is
      Port : constant Natural := Facility.Log_Connection.Port;
   begin
      return Port;
   end Get_Host_Port;

   -------------------------------------------------------------------------

   function Get_Level_Column_Name (Facility : Instance) return String is
   begin
      return To_String (Facility.Log_Table.Level_Column);
   end Get_Level_Column_Name;

   -------------------------------------------------------------------------

   function Get_Message_Column_Name (Facility : Instance) return String is
   begin
      return To_String (Facility.Log_Table.Message_Column);
   end Get_Message_Column_Name;

   -------------------------------------------------------------------------

   function Get_Table_Name (Facility : Instance) return String is
   begin
      return To_String (Facility.Log_Table.Name);
   end Get_Table_Name;

   -------------------------------------------------------------------------

   function Get_Timestamp_Column_Name (Facility : Instance) return String is
   begin
      return To_String (Facility.Log_Table.Timestamp_Column);
   end Get_Timestamp_Column_Name;

   -------------------------------------------------------------------------

   function Is_SQL_Trace (Facility : Instance) return Boolean is
   begin
      return Facility.Log_Connection.Is_Trace;
   end Is_SQL_Trace;

   -------------------------------------------------------------------------

   procedure Set_Credentials
     (Facility : in out Instance;
      Username :        String;
      Password :        String)
   is
   begin
      Facility.Log_Connection.Set_User_Password
        (User_Name     => Username,
         User_Password => Password);
   end Set_Credentials;

   -------------------------------------------------------------------------

   procedure Set_DB_Name (Facility : in out Instance; DB_Name : String) is
   begin
      Facility.Log_Connection.Set_DB_Name (DB_Name => DB_Name);
   end Set_DB_Name;

   -------------------------------------------------------------------------

   procedure Set_Host_Address
     (Facility : in out Instance;
      Address  :        String)
   is
   begin
      Facility.Log_Connection.Set_Host_Address (Address);
   end Set_Host_Address;

   -------------------------------------------------------------------------

   procedure Set_Host_Name (Facility : in out Instance; Hostname : String) is
   begin
      Facility.Log_Connection.Set_Host_Name (Hostname);
   end Set_Host_Name;

   -------------------------------------------------------------------------

   procedure Set_Host_Port (Facility : in out Instance; Port : Natural) is
   begin
      Facility.Log_Connection.Set_Port (Port);
   end Set_Host_Port;

   -------------------------------------------------------------------------

   procedure Set_Level_Column_Name
     (Facility    : in out Instance;
      Column_Name :        String)
   is
   begin
      Facility.Log_Table.Level_Column :=
        To_Unbounded_String (Column_Name);
   end Set_Level_Column_Name;

   -------------------------------------------------------------------------

   procedure Set_Message_Column_Name
     (Facility    : in out Instance;
      Column_Name :        String)
   is
   begin
      Facility.Log_Table.Message_Column :=
        To_Unbounded_String (Column_Name);
   end Set_Message_Column_Name;

   -------------------------------------------------------------------------

   procedure Set_SQL_Trace
     (Facility : in out Instance;
      Filename :        String;
      Mode     :        APQ.Trace_Mode_Type)
   is
   begin
      Facility.Trace_Filename := To_Unbounded_String (Filename);
      Facility.Trace_Mode := Mode;
   end Set_SQL_Trace;

   -------------------------------------------------------------------------

   procedure Set_Table_Name
     (Facility   : in out Instance;
      Table_Name :        String)
   is
   begin
      Facility.Log_Table.Name := To_Unbounded_String (Table_Name);
   end Set_Table_Name;

   -------------------------------------------------------------------------

   procedure Set_Timestamp_Column_Name
     (Facility    : in out Instance;
      Column_Name :        String)
   is
   begin
      Facility.Log_Table.Timestamp_Column :=
        To_Unbounded_String (Column_Name);
   end Set_Timestamp_Column_Name;

   -------------------------------------------------------------------------

   procedure Setup (Facility : in out Instance) is
   begin
      Facility.Log_Connection.Set_Trace (False);
   end Setup;

   -------------------------------------------------------------------------

   procedure Teardown (Facility : in out Instance) is
   begin
      --  Close db connection if still open.
      Facility.Close_Connection;
   end Teardown;

   -------------------------------------------------------------------------

   procedure Toggle_SQL_Trace
     (Facility : in out Instance;
      State    :        Boolean)
   is
   begin
      Facility.Log_Connection.Set_Trace (Trace_On => State);
   end Toggle_SQL_Trace;

   -------------------------------------------------------------------------

   procedure Write
     (Facility : Instance;
      Level    : Log_Level := Info;
      Msg      : String)
   is
      use APQ.PostgreSQL.Client;

      C : Connection_Type;
      Q : Query_Type;
   begin
      --  Clone connection since Facility is an "in" parameter
      C.Connect (Same_As => Facility.Log_Connection);

      --  Open SQL trace if enabled
      if Facility.Is_SQL_Trace then
         C.Open_DB_Trace (Filename => To_String (Facility.Trace_Filename),
                          Mode     => Facility.Trace_Mode);
      end if;

      Q.Prepare (SQL => "INSERT INTO ");

      Q.Append (SQL   => Facility.Get_Table_Name,
                After => " (");

      Q.Append (SQL   => Facility.Get_Level_Column_Name,
                After => ", ");

      Q.Append (SQL   => Facility.Get_Timestamp_Column_Name,
                After => ", ");

      Q.Append (SQL   => Facility.Get_Message_Column_Name,
                After => ") ");
      Q.Append (SQL   => "VALUES (");

      Q.Append (SQL   => "'" & Log_Level'Image (Level) & "'",
                After => ", ");

      Q.Append (SQL   => "now()",
                After => ", ");

      Q.Append (SQL   => "'" & Msg &"'",
                After => ");");

      Execute (Query      => Q,
               Connection => C);

      --  Close SQL trace if enabled
      if Facility.Is_SQL_Trace then
         C.Close_DB_Trace;
      end if;

      C.Disconnect;
   end Write;

end Alog.Facilities.Pgsql;