ada-util icon indicating copy to clipboard operation
ada-util copied to clipboard

Change the log time from UTC to Local Time

Open Regentag opened this issue 1 year ago • 2 comments

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.

Regentag avatar Jan 23 '24 14:01 Regentag

Thanks for your suggestion:

  • the default is now local time,
  • there is now a configuration option .utc which can be defined to true to switch to the UTC time when formatting dates.

stcarrez avatar Jan 28 '24 14:01 stcarrez

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.

stcarrez avatar Feb 04 '24 22:02 stcarrez