Added possibility to log to stderr

This commit is contained in:
Markus Vogt 2018-12-17 11:47:29 +01:00 committed by Adrian-Ken Rueegsegger
parent f06f3661b8
commit 22ab479bd6
4 changed files with 33 additions and 1 deletions

View File

@ -33,7 +33,8 @@ package body Alog.Facilities.File_Descriptor is
is
use Ada.Text_IO;
begin
if Facility.Log_File_Ptr /= Standard_Output
if (Facility.Log_File_Ptr /= Standard_Output
and Facility.Log_File_Ptr /= Standard_Error)
and Is_Open (File => Facility.Log_File)
then
if Remove then
@ -56,6 +57,14 @@ package body Alog.Facilities.File_Descriptor is
-------------------------------------------------------------------------
procedure Set_Log_Stderr (Facility : in out Instance)
is
begin
Facility.Log_File_Ptr := Ada.Text_IO.Standard_Error;
end Set_Log_Stderr;
-------------------------------------------------------------------------
procedure Set_Logfile
(Facility : in out Instance;
Path : String;

View File

@ -35,6 +35,9 @@ package Alog.Facilities.File_Descriptor is
procedure Teardown (Facility : in out Instance);
-- Implementation of Teardown-procedure.
procedure Set_Log_Stderr (Facility : in out Instance);
-- Enable logging to stderr.
procedure Set_Logfile
(Facility : in out Instance;
Path : String;

View File

@ -84,6 +84,9 @@ package body Facility_Tests.FD is
T.Add_Test_Routine
(Routine => Set_Invalid_Logfile_Fd'Access,
Name => "set invalid logfile");
T.Add_Test_Routine
(Routine => Set_Stderr'Access,
Name => "set standard error as logfile");
T.Add_Test_Routine
(Routine => Write_Message_Fd'Access,
Name => "log a fd message");
@ -125,6 +128,20 @@ package body Facility_Tests.FD is
-------------------------------------------------------------------------
procedure Set_Stderr is
use type Ada.Text_IO.File_Access;
F : File_Descriptor.Instance;
begin
Assert (Condition => F.Get_Logfile /= Ada.Text_IO.Standard_Error,
Message => "logfile already set to stderr");
F.Set_Log_Stderr;
Assert (Condition => F.Get_Logfile = Ada.Text_IO.Standard_Error,
Message => "logfile not set to stderr");
end Set_Stderr;
-------------------------------------------------------------------------
procedure Set_Valid_Logfile_Fd is
use Ada.Text_IO;
F : File_Descriptor.Instance;

View File

@ -35,6 +35,9 @@ package Facility_Tests.FD is
procedure Set_Invalid_Logfile_Fd;
-- Set illegal Fd test.
procedure Set_Stderr;
-- Set stderr Fd test.
procedure Write_Message_Fd;
-- Test message writing.