From 8d23905093ecf9f9e008c189b51714b5a8c2ca08 Mon Sep 17 00:00:00 2001 From: Björn Persson Date: Tue, 22 Jan 2013 01:09:00 +0100 Subject: minor reformatting and two comments --- system_log.adb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/system_log.adb b/system_log.adb index 71da109..b9d5d4e 100644 --- a/system_log.adb +++ b/system_log.adb @@ -1,5 +1,5 @@ -- System_Log, a binding to the Unix syslog functions --- Copyright 2009 B. Persson, Bjorn@Rombobeorn.se +-- Copyright 2009 - 2013 B. Persson, Bjorn@Rombobeorn.se -- -- This library is free software: you can redistribute it and/or modify it -- under the terms of the GNU General Public License version 3, as published @@ -11,6 +11,7 @@ with Ada.Unchecked_Conversion; package body System_Log is + Facility_Numbers : constant array(Log_Facility) of int := (Kernel => 0 * 8, -- LOG_KERN User => 1 * 8, -- LOG_USER @@ -43,6 +44,9 @@ package body System_Log is Debug => 7); -- LOG_DEBUG Name_Storage : chars_ptr := Null_Ptr; + -- The name that is passed to Open_Log is saved in Name_Storage because the + -- C library doesn't save it. + procedure Open_Log(Source_Name : in String; Facility : in Log_Facility; @@ -55,10 +59,12 @@ package body System_Log is LOG_CONS : constant := 2; -- log on the console if errors in sending LOG_NDELAY : constant := 8; -- don't delay open LOG_PERROR : constant := 32; -- log to stderr as well + procedure openlog(ident : in chars_ptr; option : in int; facility : in int); - pragma import(C, openlog, "openlog"); + pragma Import(C, openlog, "openlog"); + Options : int := 0; begin Name_Storage := New_String(Source_Name); @@ -77,17 +83,20 @@ package body System_Log is openlog(Name_Storage, Options, Facility_Numbers(Facility)); end Open_Log; + procedure Set_Log_Levels(New_Levels : in Log_Levels) is Dummy : Log_Levels; begin Set_Log_Levels(New_Levels, Dummy); end Set_Log_Levels; + procedure Set_Log_Levels(New_Levels : in Log_Levels; Old_Levels : out Log_Levels) is function setlogmask(mask : int) return int; - pragma import(C, setlogmask, "setlogmask"); + pragma Import(C, setlogmask, "setlogmask"); + Bits : constant := Log_Level'Pos(Log_Level'Last) + 1; type Mask is range 0 .. 2 ** Bits - 1; for Mask'Size use Bits; @@ -96,9 +105,12 @@ package body System_Log is function To_Levels is new Ada.Unchecked_Conversion(Source => Mask, Target => Log_Levels); begin + -- Convert the input array of Boolean to a number, pass that to + -- setlogmask, and convert the output in the other direction. Old_Levels := To_Levels(Mask(setlogmask(int(To_Mask(New_Levels))))); end Set_Log_Levels; + procedure Set_Log_Threshold(Threshold : in Log_Level) is Levels : Log_Levels := (others => False); begin @@ -106,18 +118,22 @@ package body System_Log is Set_Log_Levels(Levels); end Set_Log_Threshold; + procedure syslog(priority : in int; format : in char_array; message : in char_array); - pragma import(C, syslog, "syslog"); + pragma Import(C, syslog, "syslog"); + Simple_Format : constant char_array := To_C("%s"); + procedure Log(Level : in Log_Level; Message : in String) is begin syslog(Level_Numbers(Level), Simple_Format, To_C(Message)); end Log; + procedure Log(Facility : in Log_Facility; Level : in Log_Level; Message : in String) @@ -127,12 +143,14 @@ package body System_Log is Simple_Format, To_C(Message)); end Log; + procedure Close_Log is procedure closelog; - pragma import(C, closelog, "closelog"); + pragma Import(C, closelog, "closelog"); begin closelog; Free(Name_Storage); end Close_Log; + end System_Log; -- cgit v1.2.3