ada-util
ada-util copied to clipboard
Change the log time from UTC to Local Time
When printing the time to the log, the current implementation uses the Ada.Calendar.Formatting.Image
procedure. This causes the time to be recorded in UTC rather than the system's Local Time. It is hard-coded into the Format
function in the /src/base/log/util-log-appenders.adb
file.
I am using GNAT on Windows. System Time on my computer is UTC+9 (Seoul).
My Program:
procedure Init is
L : constant Loggers.Logger := Loggers.Create ("pdns");
begin
Util.Log.Loggers.Initialize ("log.properties");
L.Info ("UTC = " & Ada.Calendar.Formatting.Image (Ada.Calendar.Clock));
L.Info ("Local = " & Ada.Calendar.Formatting.Local_Image (Ada.Calendar.Clock));
end Init;
Result:
C:\Users\Regentag\Desktop\Ada\pdns\bin\pdns.exe
[2024-01-23 14:40:48] INFO : UTC = 2024-01-23 14:40:48
[2024-01-23 14:40:48] INFO : Local = 2024-01-23 23:40:48
[2024-01-23 23:40:48] process terminated successfully, elapsed time: 00.31s
I propose to modify the time output function to be displayed in system local time using the 'Ada.Calendar.Formating.Local_Image' procedure.
Thanks for your suggestion:
- the default is now local time,
- there is now a configuration option
.utc
which can be defined totrue
to switch to the UTC time when formatting dates.
The Local_Image
is not available on GNAT 10 so it fails to build on Ubuntu 22.04 now. It's ok with GCC 12 and above.