1-- 2-- Copyright (c) 2019, 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 Alog.Maps; 24 25-- Logging policy database package. This package provides type definitions to 26-- implement identifier-based filtering. 27package Alog.Policy_DB is 28 29 protected type Protected_Policy_DB is 30 31 procedure Set_Default_Loglevel (Level : Log_Level); 32 -- Set given loglevel as default loglevel. 33 34 function Get_Default_Loglevel return Log_Level; 35 -- Return current default loglevel. 36 37 procedure Set_Loglevel 38 (Identifier : String; 39 Level : Log_Level); 40 -- Set given loglevel for specified identifier string. If the identifier 41 -- is already present the loglevel is updated. Identifier strings are 42 -- case-sensitive. 43 -- 44 -- Use wildcards to specify a loglevel for a range of identifiers. 45 -- Identifier hierarchies are separated by dots, the wildcard is '*'. 46 -- The following example sets a Debug loglevel for all log-identifiers 47 -- in Foo.Bar (including Foo.Bar). 48 -- 49 -- Example: 50 -- Foo.Bar.* = Debug 51 -- 52 -- Direct matches take precedence over wildcard matches. In the 53 -- following example the loglevel for identifier 'Foo.Bar' is 54 -- explicitly set to Info. 55 -- 56 -- Example: 57 -- Foo.Bar = Info 58 -- Foo.Bar.* = Debug 59 60 procedure Set_Loglevel (Identifiers : Maps.Wildcard_Level_Map); 61 -- Apply loglevels for identifiers stored in map. 62 63 function Get_Loglevel (Identifier : String) return Log_Level; 64 -- Return loglevel for given identifier string. Raises No_Ident_Loglevel 65 -- exception if no entry for given identifier is found (exact match 66 -- only, no wildcard lookup). 67 68 function Lookup (Identifier : String) return Log_Level; 69 -- Return loglevel for given identifier string or the closest wildcard 70 -- match. If no associated loglevel is found the default loglevel is 71 -- returned. 72 73 procedure Reset; 74 -- Reset the logging policy database to the initial state. 75 76 function Accept_ID 77 (Identifier : String; 78 Level : Log_Level) 79 return Boolean; 80 -- Returns True if the given loglevel is accepted for a specified 81 -- identifier. The loglevel is compared against the default loglevel if 82 -- no match for the given identifier is found. 83 84 private 85 86 Ident_Levels : Maps.Wildcard_Level_Map; 87 -- Identifier based loglevels. 88 89 Current_Default_Loglevel : Log_Level := Log_Level'First; 90 -- Current default loglevel. 91 end Protected_Policy_DB; 92 93 No_Ident_Loglevel : exception; 94 -- Will be raised if loglevel is not found for a requested identifier. 95 96end Alog.Policy_DB; 97