From 8dbc94afe067831f45ca5985be2ecf75d7ae2f8a Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Wed, 31 Jan 2018 02:36:11 +0100 Subject: [PATCH] Better logging --- src/alire-os_lib.adb | 9 ++++++--- src/alire-os_lib.ads | 5 +++++ src/alire.adb | 16 ++++++++++++++++ src/alire.ads | 15 +++++++++------ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/alire.adb diff --git a/src/alire-os_lib.adb b/src/alire-os_lib.adb index 496f9c30..c7217d2e 100644 --- a/src/alire-os_lib.adb +++ b/src/alire-os_lib.adb @@ -1,4 +1,3 @@ -with Ada.Directories; with GNAT.OS_Lib; package body Alire.OS_Lib is @@ -27,8 +26,12 @@ package body Alire.OS_Lib is -- FIXME: memory leaks function Spawn (Command : String; Arguments : String) return Integer is - (Spawn (Locate_In_Path (Command), - Argument_String_To_List (Arguments).all)); + begin + Log ("Spawning: " & Command & " " & Arguments, Verbose); + return + (Spawn (Locate_In_Path (Command), + Argument_String_To_List (Arguments).all)); + end Spawn; ----------- -- Spawn -- diff --git a/src/alire-os_lib.ads b/src/alire-os_lib.ads index 6456744a..08af1842 100644 --- a/src/alire-os_lib.ads +++ b/src/alire-os_lib.ads @@ -1,3 +1,4 @@ +with Ada.Directories; with Ada.Finalization; package Alire.OS_Lib is @@ -16,6 +17,10 @@ package Alire.OS_Lib is function Enter_Folder (Path : String) return Folder_Guard; + function "/" (L, R : String) return String is + (Ada.Directories.Compose (L, R)); + -- Shorthand for path composition + private type Folder_Guard (Original_Len : Positive) is new Ada.Finalization.Limited_Controlled with record diff --git a/src/alire.adb b/src/alire.adb new file mode 100644 index 00000000..24e3e123 --- /dev/null +++ b/src/alire.adb @@ -0,0 +1,16 @@ +with GNAT.IO; + +package body Alire is + + procedure Log (S : String; Level : Verbosities := Terse) is + begin + if Level >= Verbosity then + GNAT.IO.Put_Line + ((case Level is + when Terse => "", + when Verbose => ": ", + when Debug => "+++ ") & S); + end if; + end Log; + +end Alire; diff --git a/src/alire.ads b/src/alire.ads index ae16d97c..5c81c04b 100644 --- a/src/alire.ads +++ b/src/alire.ads @@ -1,7 +1,5 @@ private with Ada.Containers.Indefinite_Holders; -private with GNAT.IO; -- For debugging purposes, FIXME getting rid of it and using some proper Trace lib - with Semantic_Versioning; package Alire with Preelaborate is @@ -38,6 +36,14 @@ package Alire with Preelaborate is function Version (M : Milestone) return Semantic_Versioning.Version; + -- LOGGING -- + + type Verbosities is (Debug, Verbose, Terse); + + Verbosity : Verbosities := Terse; + + procedure Log (S : String; Level : Verbosities := Terse); + private use all type Semantic_Versioning.Version; @@ -72,9 +78,6 @@ private function Project (M : Milestone) return Project_Name is (M.Name); - function Version (M : Milestone) return Semantic_Versioning.Version is (M.Version); - - - procedure Log (S : String) renames GNAT.IO.Put_Line; + function Version (M : Milestone) return Semantic_Versioning.Version is (M.Version); end Alire;