stcarrez / ada-util

Ada Utility Library - Composing streams, processes, logs, serialization, encoders and more
Apache License 2.0
69 stars 14 forks source link

Change the log time from UTC to Local Time #48

Closed Regentag closed 4 months ago

Regentag commented 9 months ago

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.

stcarrez commented 9 months ago

Thanks for your suggestion:

stcarrez commented 9 months ago

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.