/usr/share/ada/adainclude/log4ada/log4ada-events.adb is in liblog4ada2-dev 1.2-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 | ------------------------------------------------------------------------------
-- Log4Ada --
-- --
-- Copyright (C) 2007 --
-- X. Grave CNRS --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or (at --
-- your option) any later version. --
-- --
-- This library 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 --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
package body Log4ada.Events is
use Ada.Strings.Unbounded;
use Ada.Exceptions;
Event_Name : constant Unbounded_String :=
To_Unbounded_String ("log4ada:event");
---------------
-- New_Event --
---------------
function New_Event (Location_Information : String;
Logger_Name : String;
Level : Level_Type;
Timestamp : Integer;
Message : String)
return Event_Type is
begin
return (Name => Event_Name,
Location_Information =>
To_Unbounded_String (Location_Information),
Logger_Name => To_Unbounded_String (Logger_Name),
Level => Level,
Timestamp => Timestamp,
Message => To_Unbounded_String (Message),
Exception_Present => False,
Exception_To_Send_Name => Null_Unbounded_String,
Exception_To_Send_Message => Null_Unbounded_String);
end New_Event;
function New_Event
(Location_Information : String;
Logger_Name : String;
Level : Level_Type;
Timestamp : Integer;
Message : String;
Exception_To_Send : Ada.Exceptions.Exception_Occurrence)
return Event_Type
is
begin
return (Name => Event_Name,
Location_Information =>
To_Unbounded_String (Location_Information),
Logger_Name => To_Unbounded_String (Logger_Name),
Level => Level,
Timestamp => Timestamp,
Message => To_Unbounded_String (Message),
Exception_Present => True,
Exception_To_Send_Name =>
To_Unbounded_String (Exception_Name (Exception_To_Send)),
Exception_To_Send_Message =>
To_Unbounded_String (Exception_Message (Exception_To_Send)));
end New_Event;
------------------------------
-- Get_Location_Information --
------------------------------
function Get_Location_Information (Event : Event_Type) return String is
begin
return To_String (Event.Location_Information);
end Get_Location_Information;
function Get_Logger_Name (Event : Event_Type) return String is
begin
return To_String (Event.Logger_Name);
end Get_Logger_Name;
---------------
-- Get_Level --
---------------
function Get_Level (Event : Event_Type) return Level_Type is
begin
return Event.Level;
end Get_Level;
-------------------
-- Get_Timestamp --
-------------------
function Get_Timestamp (Event : Event_Type) return Integer is
begin
return Event.Timestamp;
end Get_Timestamp;
-----------------
-- Get_Message --
-----------------
function Get_Message (Event : Event_Type) return String is
begin
return To_String (Event.Message);
end Get_Message;
-------------------
-- Get_Exception --
-------------------
function Exception_Present (Event : Event_Type) return Boolean is
begin
return Event.Exception_Present;
end Exception_Present;
function Get_Exception_Name
(Event : Event_Type)
return String
is
begin
return To_String (Event.Exception_To_Send_Name);
end Get_Exception_Name;
function Get_Exception_Message (Event : Event_Type) return String is
begin
return To_String (Event.Exception_To_Send_Message);
end Get_Exception_Message;
Event_Separator : constant String := "<log4Ada_Tag>";
Missing_Separator : exception;
function Get_First_Value (Work_Event_String : Unbounded_String)
return String;
function Get_First_Value_Unbounded (Work_Event_String : Unbounded_String)
return Unbounded_String;
procedure Cut_First_Value (Work_Event_String : in out Unbounded_String);
function To_Event (Event_String : String) return Event_Type is
Event : Event_Type;
Work_Event_String : Unbounded_String :=
To_Unbounded_String (Event_String);
begin
Event.Name := Get_First_Value_Unbounded (Work_Event_String);
Cut_First_Value (Work_Event_String);
Event.Location_Information :=
Get_First_Value_Unbounded (Work_Event_String);
Cut_First_Value (Work_Event_String);
Event.Level := Level_Type'Value (Get_First_Value (Work_Event_String));
Cut_First_Value (Work_Event_String);
Event.Timestamp := Integer'Value (Get_First_Value (Work_Event_String));
Cut_First_Value (Work_Event_String);
Event.Message := Get_First_Value_Unbounded (Work_Event_String);
Cut_First_Value (Work_Event_String);
Event.Logger_Name := Get_First_Value_Unbounded (Work_Event_String);
Cut_First_Value (Work_Event_String);
Event.Exception_Present :=
Boolean'Value (Get_First_Value (Work_Event_String));
if Event.Exception_Present then
Cut_First_Value (Work_Event_String);
Event.Exception_To_Send_Name :=
Get_First_Value_Unbounded (Work_Event_String);
Cut_First_Value (Work_Event_String);
Event.Exception_To_Send_Message :=
Get_First_Value_Unbounded (Work_Event_String);
else
Event.Exception_To_Send_Name := Null_Unbounded_String;
Event.Exception_To_Send_Message := Null_Unbounded_String;
end if;
return Event;
end To_Event;
function To_String (Event : Event_Type) return String is
String_To_Return : Unbounded_String := Event_Name;
begin
String_To_Return := String_To_Return &
Event_Separator & Event.Location_Information;
String_To_Return := String_To_Return &
Event_Separator & Event.Level'Img;
String_To_Return := String_To_Return &
Event_Separator & Event.Timestamp'Img;
String_To_Return := String_To_Return &
Event_Separator & Event.Message;
String_To_Return := String_To_Return &
Event_Separator & Event.Logger_Name;
String_To_Return := String_To_Return &
Event_Separator & Event.Exception_Present'Img;
String_To_Return := String_To_Return &
Event_Separator & Event.Exception_To_Send_Name;
String_To_Return := String_To_Return &
Event_Separator & Event.Exception_To_Send_Message;
return To_String (String_To_Return);
end To_String;
function Get_First_Value (Work_Event_String : Unbounded_String)
return String is
begin
return To_String (Get_First_Value_Unbounded (Work_Event_String));
end Get_First_Value;
function Get_First_Value_Unbounded (Work_Event_String : Unbounded_String)
return Unbounded_String is
Separator_Position : constant Natural := Index (Work_Event_String,
Event_Separator);
begin
if Separator_Position = 0 then
return Work_Event_String;
end if;
return Head (Work_Event_String, Separator_Position - 1);
end Get_First_Value_Unbounded;
procedure Cut_First_Value (Work_Event_String : in out Unbounded_String) is
Separator_Position : constant Natural := Index (Work_Event_String,
Event_Separator);
begin
if Separator_Position = 0 then
raise Missing_Separator;
end if;
Tail (Work_Event_String,
Length (Work_Event_String) -
Separator_Position -
Event_Separator'Length + 1);
end Cut_First_Value;
end Log4ada.Events;
|