Skip to content

feat: add UTC timestamps to all console log entries#3709

Open
JerryNixon with Copilot wants to merge 3 commits into
mainfrom
copilot/add-timestamp-to-logs
Open

feat: add UTC timestamps to all console log entries#3709
JerryNixon with Copilot wants to merge 3 commits into
mainfrom
copilot/add-timestamp-to-logs

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Why make this change?

Console log output lacks timestamps, making it difficult to correlate events or determine when entries occurred — especially under high request volume.

What is this change?

Prepends an ISO 8601 UTC timestamp with millisecond precision to every console log entry:

2026-07-07T14:01:01.344Z info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 GET http://localhost:5000/graphql - - -
2026-07-07T14:01:01.345Z dbug: Azure.DataApiBuilder.Core.AuthenticationHelpers.ClientRoleHeaderAuthenticationMiddleware[0]
      bfa3a6ee AuthN state: Anonymous. Role: Anonymous.
  • src/Service/Program.cs — Replaces AddConsole() with AddSimpleConsole(TimestampFormat, UseUtcTimestamp) in both GetLoggerFactoryForLogLevel (startup logger) and CreateHostBuilder.ConfigureLogging (web host logger). MCP stdio path additionally uses Services.Configure<ConsoleLoggerOptions> for stderr routing, keeping a single registered provider.
  • src/Cli/CustomLoggerProvider.cs — Prepends DateTime.UtcNow.ToString(UtcTimestampFormat) before the abbreviated level label in the CLI's custom console logger (both standard and MCP stdio paths). Timestamp format extracted to a named constant.
  • src/Cli.Tests/CustomLoggerTests.cs — Updates LogOutput_UsesAbbreviatedLogLevelLabels assertion from StartsWith to Contains since the timestamp now precedes the level label.

How was this tested?

  • Integration Tests
  • Unit Tests

Sample Request(s)

No REST/GraphQL/CLI request changes — output-only behavioral change visible when running dab start.

Copilot AI linked an issue Jul 8, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add timestamp to logs for better tracking feat: add UTC timestamps to all console log entries Jul 8, 2026
Copilot AI requested a review from JerryNixon July 8, 2026 16:42
@JerryNixon JerryNixon marked this pull request as ready for review July 8, 2026 17:54
Copilot AI review requested due to automatic review settings July 8, 2026 17:54
@JerryNixon JerryNixon added cli telemetry feature requests/ bug reports related to telemetry labels Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make console logs easier to correlate by prepending an ISO 8601 UTC timestamp (millisecond precision) to console output emitted by both the Service host and the CLI custom logger.

Changes:

  • Updated Service logging to use the console “simple” formatter with UTC timestamp settings (including MCP stdio stderr routing for the startup logger factory).
  • Updated the CLI custom console logger to prepend a UTC timestamp before the abbreviated log level label.
  • Adjusted CLI unit tests for the new timestamp-prefixed output (but the updated assertion is now too permissive).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/Service/Program.cs Switches console logging to include UTC timestamps; MCP stdio path continues to keep stdout clean.
src/Cli/CustomLoggerProvider.cs Prepends UTC timestamps to CLI log prefixes for both standard and MCP stdio modes.
src/Cli.Tests/CustomLoggerTests.cs Updates assertions to account for timestamps in log output.

// Apply colors so the abbreviation matches the visual style of engine logs.
// try/finally guarantees the original colors are restored even if Write throws,
// otherwise the console would be left tinted (e.g. red on error) for subsequent output.
string mcpTimestamp = DateTime.UtcNow.ToString(UtcTimestampFormat);
}

TextWriter writer = logLevel >= LogLevel.Error ? Console.Error : Console.Out;
string timestamp = DateTime.UtcNow.ToString(UtcTimestampFormat);
Comment on lines +80 to +81
Assert.IsTrue(actual.Contains(expectedPrefix),
$"Expected output to contain '{expectedPrefix}' but got: '{actual}'");
Comment thread src/Service/Program.cs
Comment on lines +198 to +202
logging.AddSimpleConsole(options =>
{
options.TimestampFormat = "yyyy-MM-dd'T'HH:mm:ss.fff'Z' ";
options.UseUtcTimestamp = true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli telemetry feature requests/ bug reports related to telemetry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add timestamp to logs

3 participants