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

Add UTC timestamp display option #7602

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Controls/LogViewer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@{
var hasPrefix = false;
}
@if (ShowTimestamp && context.Timestamp is { } timestamp)
@if (TimestampDisplayMode is not TimestampDisplayMode.None && context.Timestamp is { } timestamp)
{
hasPrefix = true;
<span class="timestamp" title="@FormatHelpers.FormatDateTime(TimeProvider, timestamp, MillisecondsDisplay.Full, CultureInfo.CurrentCulture)">@GetDisplayTimestamp(timestamp)</span>
Expand Down
12 changes: 9 additions & 3 deletions src/Aspire.Dashboard/Components/Controls/LogViewer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Aspire.Dashboard.Components;
/// </summary>
public sealed partial class LogViewer
{
private readonly bool _convertTimestampsFromUtc = true;
private LogEntries? _logEntries;
private bool _logsChanged;

Expand All @@ -32,7 +31,7 @@ public sealed partial class LogViewer
public LogEntries? LogEntries { get; set; } = null!;

[Parameter]
public bool ShowTimestamp { get; set; }
public TimestampDisplayMode TimestampDisplayMode { get; set; }
Comment on lines 33 to +34
Copy link
Member

Choose a reason for hiding this comment

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

I think these should be different bool parameters:

ShowTimestamp
IsTimestampUtc


protected override void OnParametersSet()
{
Expand Down Expand Up @@ -74,7 +73,7 @@ private void OnBrowserResize(object? o, EventArgs args)

private string GetDisplayTimestamp(DateTimeOffset timestamp)
{
var date = _convertTimestampsFromUtc ? TimeProvider.ToLocal(timestamp) : timestamp.DateTime;
var date = TimestampDisplayMode is TimestampDisplayMode.Local ? TimeProvider.ToLocal(timestamp) : timestamp.DateTime;

return date.ToString(KnownFormats.ConsoleLogsUITimestampFormat, CultureInfo.InvariantCulture);
}
Expand All @@ -87,3 +86,10 @@ public ValueTask DisposeAsync()
return ValueTask.CompletedTask;
}
}

public enum TimestampDisplayMode
{
None,
Local,
Utc
}
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</MobilePageTitleToolbarSection>

<MainSection>
<LogViewer LogEntries="@_logEntries" ShowTimestamp="@_showTimestamp" />
<LogViewer LogEntries="@_logEntries" TimestampDisplayMode="@_timestampDisplayMode" />
</MainSection>
</AspirePageContentLayout>
</div>
41 changes: 28 additions & 13 deletions src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private sealed class ConsoleLogsSubscription
private readonly List<MenuButtonItem> _resourceMenuItems = new();

// State
private bool _showTimestamp;
private TimestampDisplayMode _timestampDisplayMode;
public ConsoleLogsViewModel PageViewModel { get; set; } = null!;
private IDisposable? _consoleLogsFiltersChangedSubscription;
private ConsoleLogsFilters _consoleLogFilters = new();
Expand All @@ -121,10 +121,14 @@ protected override async Task OnInitializedAsync()
await InvokeAsync(StateHasChanged);
});

var timestampStorageResult = await LocalStorage.GetUnprotectedAsync<ConsoleLogConsoleSettings>(BrowserStorageKeys.ConsoleLogConsoleSettings);
if (timestampStorageResult.Value?.ShowTimestamp is { } showTimestamp)
var consoleSettingsResult = await LocalStorage.GetUnprotectedAsync<ConsoleLogConsoleSettings>(BrowserStorageKeys.ConsoleLogConsoleSettings);
if (consoleSettingsResult.Value is { } consoleSettings)
{
_showTimestamp = showTimestamp;
_timestampDisplayMode = consoleSettings.TimestampDisplayMode;
}
else
{
_timestampDisplayMode = TimestampDisplayMode.Local;
}

await ConsoleLogsManager.EnsureInitializedAsync();
Expand Down Expand Up @@ -286,20 +290,31 @@ private void UpdateMenuButtons()
Icon = new Icons.Regular.Size16.ArrowDownload()
});

if (!_showTimestamp)
if (_timestampDisplayMode is not TimestampDisplayMode.Local)
{
_logsMenuItems.Add(new()
{
OnClick = () => ToggleTimestampAsync(showTimestamp: true),
Text = Loc[nameof(Dashboard.Resources.ConsoleLogs.ConsoleLogsTimestampShow)],
OnClick = () => ToggleTimestampAsync(displayMode: TimestampDisplayMode.Local),
Text = Loc[nameof(Dashboard.Resources.ConsoleLogs.ConsoleLogsTimestampShowLocal)],
Icon = new Icons.Regular.Size16.CalendarClock()
});
}
else

if (_timestampDisplayMode is not TimestampDisplayMode.Utc)
{
_logsMenuItems.Add(new()
{
OnClick = () => ToggleTimestampAsync(displayMode: TimestampDisplayMode.Utc),
Text = Loc[nameof(Dashboard.Resources.ConsoleLogs.ConsoleLogsTimestampShowUtc)],
Icon = new Icons.Regular.Size16.CalendarAdd()
});
}

if (_timestampDisplayMode is not TimestampDisplayMode.None)
{
_logsMenuItems.Add(new()
{
OnClick = () => ToggleTimestampAsync(showTimestamp: false),
OnClick = () => ToggleTimestampAsync(displayMode: TimestampDisplayMode.None),
Text = Loc[nameof(Dashboard.Resources.ConsoleLogs.ConsoleLogsTimestampHide)],
Icon = new Icons.Regular.Size16.DismissSquareMultiple()
});
Expand Down Expand Up @@ -332,10 +347,10 @@ private void UpdateMenuButtons()
}
}

private async Task ToggleTimestampAsync(bool showTimestamp)
private async Task ToggleTimestampAsync(TimestampDisplayMode displayMode)
{
await LocalStorage.SetUnprotectedAsync(BrowserStorageKeys.ConsoleLogConsoleSettings, new ConsoleLogConsoleSettings(ShowTimestamp: showTimestamp));
_showTimestamp = showTimestamp;
await LocalStorage.SetUnprotectedAsync(BrowserStorageKeys.ConsoleLogConsoleSettings, new ConsoleLogConsoleSettings(TimestampDisplayMode: displayMode));
_timestampDisplayMode = displayMode;

UpdateMenuButtons();
StateHasChanged();
Expand Down Expand Up @@ -609,7 +624,7 @@ public class ConsoleLogsViewModel

public record ConsoleLogsPageState(string? SelectedResource);

public record ConsoleLogConsoleSettings(bool ShowTimestamp);
public record ConsoleLogConsoleSettings(TimestampDisplayMode TimestampDisplayMode);

public Task UpdateViewModelFromQueryAsync(ConsoleLogsViewModel viewModel)
{
Expand Down
16 changes: 12 additions & 4 deletions src/Aspire.Dashboard/Resources/ConsoleLogs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 32 additions & 29 deletions src/Aspire.Dashboard/Resources/ConsoleLogs.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema

Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple

There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -163,8 +163,11 @@
<data name="ConsoleLogsResourceCommands" xml:space="preserve">
<value>Resource commands</value>
</data>
<data name="ConsoleLogsTimestampShow" xml:space="preserve">
<value>Show timestamps</value>
<data name="ConsoleLogsTimestampShowUtc" xml:space="preserve">
<value>Show UTC timestamps</value>
</data>
<data name="ConsoleLogsTimestampShowLocal" xml:space="preserve">
<value>Show local timestamps</value>
</data>
<data name="ConsoleLogsTimestampHide" xml:space="preserve">
<value>Hide timestamps</value>
Expand Down
11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ConsoleLogs.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ConsoleLogs.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ConsoleLogs.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ConsoleLogs.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ConsoleLogs.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ConsoleLogs.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ConsoleLogs.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading