Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the log time from UTC to Local Time #48

Closed
Regentag opened this issue Jan 23, 2024 · 2 comments
Closed

Change the log time from UTC to Local Time #48

Regentag opened this issue Jan 23, 2024 · 2 comments

Comments

@Regentag
Copy link

Regentag commented Jan 23, 2024

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 added a commit that referenced this issue Jan 28, 2024
- by default, print the date in local time
- add new configuration option '.utc' to format the date in local time
- add Format function to format a date according to the appender
  configuration
- update documentation
@stcarrez
Copy link
Owner

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
Copy link
Owner

stcarrez commented Feb 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants