1-- 2-- Copyright (c) 2008-2011, 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 23with Interfaces.C.Strings; 24 25package body Alog.Facilities.Syslog is 26 27 package C renames Interfaces.C; 28 29 type L_Type is mod 2 ** 3; 30 for L_Type'Size use 3; 31 32 type F_Type is mod 2 ** 8; 33 for F_Type'Size use 8; 34 35 Level_Map : constant array (Log_Level) of L_Type 36 := (Debug => 7, 37 Info => 6, 38 Notice => 5, 39 Warning => 4, 40 Error => 3, 41 Critical => 2, 42 Alert => 1, 43 Emergency => 0); 44 45 Facility_Map : constant array (Syslog_Origin) of F_Type 46 := (LOG_KERN => 0, 47 LOG_USER => 8, 48 LOG_MAIL => 16, 49 LOG_DAEMON => 24, 50 LOG_AUTH => 32, 51 LOG_SYSLOG => 40, 52 LOG_LPR => 48, 53 LOG_NEWS => 56, 54 LOG_UUCP => 64, 55 LOG_CRON => 72, 56 LOG_AUTHPRIV => 80, 57 LOG_FTP => 88, 58 LOG_LOCAL0 => 128, 59 LOG_LOCAL1 => 136, 60 LOG_LOCAL2 => 144, 61 LOG_LOCAL3 => 152, 62 LOG_LOCAL4 => 160, 63 LOG_LOCAL5 => 168, 64 LOG_LOCAL6 => 176, 65 LOG_LOCAL7 => 184); 66 67 ------------------------------------------------------------------------- 68 69 function Get_Origin (Facility : Instance) return Syslog_Origin 70 is 71 begin 72 return Facility.Origin; 73 end Get_Origin; 74 75 ------------------------------------------------------------------------- 76 77 procedure Set_Origin 78 (Facility : in out Instance; 79 Value : Syslog_Origin) 80 is 81 begin 82 Facility.Origin := Value; 83 end Set_Origin; 84 85 ------------------------------------------------------------------------- 86 87 procedure Write 88 (Facility : Instance; 89 Level : Log_Level := Info; 90 Msg : String) 91 is 92 use type C.int; 93 94 procedure Syslog_Wrapper 95 (Prio : C.int; 96 Msg : C.Strings.chars_ptr); 97 pragma Import (C, Syslog_Wrapper, "syslog_wrapper"); 98 99 C_Msg : C.Strings.chars_ptr := C.Strings.New_String (Str => Msg); 100 C_Prio : constant C.int := C.int (Level_Map (Level)) + 101 C.int (Facility_Map (Facility.Origin)); 102 begin 103 Syslog_Wrapper (Prio => C_Prio, 104 Msg => C_Msg); 105 106 C.Strings.Free (C_Msg); 107 end Write; 108 109end Alog.Facilities.Syslog; 110