logga/src/logga.ads

64 lines
2.2 KiB
Ada

with Ada.Strings.Unbounded;
private with Ada.Characters.Latin_1;
--
-- Logga is small and fast logging library for Ada projects
--
package Logga is
use Ada.Strings.Unbounded;
-- Levels determine if/when log messages will be output
type Level_Type is (Fine, Trace, Debug, Info, Warn, Error, Critical);
-- Tokens_Array_Type helps to curry arbitrary numbers of tokens into log messages
type Tokens_Array_Type is array (Positive range <>) of Unbounded_String;
--
-- Log is an object which allows logging and automatically omits log messages
-- which fall under the specified Level
type Log_Type is tagged record
Level : Level_Type := Warn;
Colors : Boolean := True;
end record;
procedure Debug (L : in Log_Type;
Message : in String);
procedure Debug (L : in Log_Type;
Message : in String;
Tokens : in Tokens_Array_Type);
procedure Info (L : in Log_Type;
Message : in String);
procedure Warn (L : in Log_Type;
Message : in String);
procedure Error (L : in Log_Type;
Message : in String);
procedure Log (L : in Log_Type;
Level : in Level_Type;
Message : in String);
-- Optimized function which will avoid creating new strings if the Debug level
-- messages would not be printed
function d (L : in Log_Type;
Token : in String) return Unbounded_String;
function d (L : in Log_Type;
Token : in Integer) return Unbounded_String;
-- T is a small helper function to convert something to an suitable token for
-- output.
--
-- NOTE: This function is not optimized and will result in new string allocation
-- regardless of the log level.
function T (Token : in String) return Unbounded_String;
function T (Token : in Integer) return Unbounded_String;
private
use Ada.Characters.Latin_1;
Red : constant String := ESC & "[0;31m";
Light_Red : constant String := ESC & "[1;31m";
Yellow : constant String := ESC & "[1;33m";
Green : constant String := ESC & "[1;32m";
Cyan : constant String := ESC & "[0;36m";
end Logga;