Skip to content

Commit

Permalink
Support disabling log patterns and showing raw log lines temporarily.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster620 committed Oct 13, 2024
1 parent 7da8cdd commit 2cf90ed
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 45 deletions.
2 changes: 1 addition & 1 deletion ULogViewer/ChangeList-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---

## 新功能
+
+ 支持在已定义[日志行格式](https://carinastudio.azurewebsites.net/ULogViewer/HowToReadAndParseLogs#LogPatterns)后暂时显示原始日志行。

## 优化
+ 允许在```编辑日志类型``````编辑动作时距分析规则``````资料来源参数``` 对话窗中使用鼠标拖动以调整项目顺序,而非原先的点击按钮。
Expand Down
2 changes: 1 addition & 1 deletion ULogViewer/ChangeList-zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---

## 新功能
+
+ 支援在已定義[日誌行格式](https://carinastudio.azurewebsites.net/ULogViewer/HowToReadAndParseLogs#LogPatterns)後暫時顯示原始日誌行。

## 改善
+ 允許在 ```編輯日誌類型``````編輯動作時距分析規則``````資料來源參數``` 對話方塊中使用滑鼠拖動以調整項目順序,而非原先的使用按鈕。
Expand Down
2 changes: 1 addition & 1 deletion ULogViewer/ChangeList.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---

## New Features
+
+ Support showing raw log lines temporarily even when [log patterns](https://carinastudio.azurewebsites.net/ULogViewer/HowToReadAndParseLogs#LogPatterns) were defined.

## Improvement
+ Allow reordering items in ```Edit log profile```, ```Edit operation duration analysis rule``` and ```Data source options``` dialogs by mouse dragging instead of clicking action button.
Expand Down
84 changes: 49 additions & 35 deletions ULogViewer/Controls/SessionView.axaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ULogViewer/Strings/Default.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ return None</sys:String>
<sys:String x:Key="String/SessionView.CopyLogText">Copy text of log for filtering</sys:String>
<sys:String x:Key="String/SessionView.CopyLogsWithFileNames">Copy logs with file names</sys:String>
<sys:String x:Key="String/SessionView.CpuUsage">CPU usage</sys:String>
<sys:String x:Key="String/SessionView.DisableLogPatterns">Show raw log lines</sys:String>
<sys:String x:Key="String/SessionView.EditConfiguration">Edit internal configuration…</sys:String>
<sys:String x:Key="String/SessionView.EditCurrentEmbeddedScriptLogDataSourceProvider">Edit embedded log data source script</sys:String>
<sys:String x:Key="String/SessionView.EditCurrentScriptLogDataSourceProvider">Edit log data source script '{0}'</sys:String>
Expand Down
1 change: 1 addition & 0 deletions ULogViewer/Strings/zh-CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ return None</sys:String>
<sys:String x:Key="String/SessionView.CopyLogText">复制筛选用日志文字</sys:String>
<sys:String x:Key="String/SessionView.CopyLogsWithFileNames">复制日志 (包含文件名称)</sys:String>
<sys:String x:Key="String/SessionView.CpuUsage">CPU 使用率</sys:String>
<sys:String x:Key="String/SessionView.DisableLogPatterns">显示原始日志行</sys:String>
<sys:String x:Key="String/SessionView.EditConfiguration">编辑內部配置…</sys:String>
<sys:String x:Key="String/SessionView.EditCurrentEmbeddedScriptLogDataSourceProvider">编辑内嵌日志资料来源脚本</sys:String>
<sys:String x:Key="String/SessionView.EditCurrentScriptLogDataSourceProvider">编辑「{0}」日志资料来源脚本</sys:String>
Expand Down
1 change: 1 addition & 0 deletions ULogViewer/Strings/zh-TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ return None</sys:String>
<sys:String x:Key="String/SessionView.CopyLogText">複製篩選用日誌文字</sys:String>
<sys:String x:Key="String/SessionView.CopyLogsWithFileNames">複製日誌 (包含檔案名稱)</sys:String>
<sys:String x:Key="String/SessionView.CpuUsage">CPU 使用率</sys:String>
<sys:String x:Key="String/SessionView.DisableLogPatterns">顯示原始日誌行</sys:String>
<sys:String x:Key="String/SessionView.EditConfiguration">編輯內部組態…</sys:String>
<sys:String x:Key="String/SessionView.EditCurrentEmbeddedScriptLogDataSourceProvider">編輯內嵌日誌資料來源腳本</sys:String>
<sys:String x:Key="String/SessionView.EditCurrentScriptLogDataSourceProvider">編輯「{0}」日誌資料來源腳本</sys:String>
Expand Down
7 changes: 7 additions & 0 deletions ULogViewer/Styles/Icons.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<StreamGeometry x:Key="Geometry/Clock.Outline">F1M75,-118.75C76.0790634155273,-118.75,77.1581268310547,-118.470886230469,78.125,-117.912658691406C80.0587539672852,-116.796203613281,81.25,-114.73291015625,81.25,-112.5L81.25,-81.25 106.25,-81.25C109.701782226563,-81.25,112.5,-78.4517822265625,112.5,-75C112.5,-71.5482177734375,109.701782226563,-68.75,106.25,-68.75L75,-68.75C71.5482177734375,-68.75,68.75,-71.5482177734375,68.75,-75L68.75,-112.5C68.75,-114.73291015625,69.9412460327148,-116.796203613281,71.875,-117.912658691406C72.8418731689453,-118.470886230469,73.9209365844727,-118.75,75,-118.75z M75,-125C47.3857612609863,-125,25,-102.614234924316,25,-75C25,-47.3857574462891,47.3857612609863,-25,75,-25C92.86328125,-25 109.36962890625,-34.5299491882324 118.30126953125,-50 127.23291015625,-65.4700546264648 127.23291015625,-84.5299530029297 118.30126953125,-100.000007629395C109.36962890625,-115.470054626465,92.86328125,-125,75,-125z M75,-137.5C109.518753051758,-137.5 137.5,-109.518753051758 137.5,-75 137.5,-40.4812507629395 109.518753051758,-12.5 75,-12.5 40.4812507629395,-12.5 12.5,-40.4812507629395 12.5,-75 12.5,-109.518753051758 40.4812507629395,-137.5 75,-137.5z</StreamGeometry>
<StreamGeometry x:Key="Geometry/Decrease">M16,18L18.29,15.71L13.41,10.83L9.41,14.83L2,7.41L3.41,6L9.41,12L13.41,8L19.71,14.29L22,12V18H16Z</StreamGeometry>
<StreamGeometry x:Key="Geometry/Diagnostic">M11.6,0 C14.03,0 16,2 16,4.8 C16,10.4 10,13.6 8,14.8 C6.418,13.85 2.333,11.65 0.6944,8 L4.453,8 L5.2,6.755 L7.6,10.76 L9.253,8 L12,8 L12,6.4 L8.347,6.4 L7.6,7.645 L5.2,3.645 L3.547,6.4 L0.168,6.4 C0.0592,5.89 0,5.357 0,4.8 C0,2 2,0 4.4,0 C5.888,0 7.2,0.8 8,1.6 C8.8,0.8 10.11,0 11.6,0 z</StreamGeometry>
<StreamGeometry x:Key="Geometry/DisableLogPatterns">M22.11 21.46L2.39 1.73L1.11 3L3.22 5.11C3.08 5.38 3 5.68 3 6V18C3 19.11 3.9 20 5 20H18.11L20.84 22.73L22.11 21.46M10.11 12H5V8H6.11L10.11 12M11 18H5V14H11V18M13 18V14.89L16.11 18H13M13 9.8L7.2 4H19C20.11 4 21 4.89 21 6V17.8L19 15.8V14H17.2L15.2 12H19V8H13V9.8Z</StreamGeometry>
<StreamGeometry x:Key="Geometry/Drawer">M3.662E-06,8.8 L14.4,8.8 L14.4,15.2 C14.4,15.64 14.04,16 13.61,16 L0.7944,16 A0.796,-0.796 0 0 1 3.662E-06,15.2 L3.662E-06,8.8 z M3.662E-06,0.7984 C3.662E-06,0.3576 0.356,0 0.7944,0 L13.61,0 C14.04,0 14.4,0.3568 14.4,0.7984 L14.4,7.2 L3.662E-06,7.2 L3.662E-06,0.7984 z M4.8,2.4 L4.8,4 L9.6,4 L9.6,2.4 L4.8,2.4 z M4.8,11.2 L4.8,12.8 L9.6,12.8 L9.6,11.2 L4.8,11.2 z</StreamGeometry>
<StreamGeometry x:Key="Geometry/EditDetailedly">M6,2C4.89,2 4,2.89 4,4V20A2,2 0 0,0 6,22H10V20.09L12.09,18H6V16H14.09L16.09,14H6V12H18.09L20,10.09V8L14,2H6M13,3.5L18.5,9H13V3.5M20.15,13C20,13 19.86,13.05 19.75,13.16L18.73,14.18L20.82,16.26L21.84,15.25C22.05,15.03 22.05,14.67 21.84,14.46L20.54,13.16C20.43,13.05 20.29,13 20.15,13M18.14,14.77L12,20.92V23H14.08L20.23,16.85L18.14,14.77Z</StreamGeometry>
<StreamGeometry x:Key="Geometry/EndTo">M0,14 L12,14 L12,16 L0,16 z M5,1.831E-007 L5,6 L0,6 L6,12 L12,6 L7,6 L7,1.831E-007 z</StreamGeometry>
Expand Down Expand Up @@ -287,6 +288,12 @@
<DrawingImage x:Key="Image/Database.Light">
<GeometryDrawing Brush="{DynamicResource Brush/Icon.Light}" Geometry="{StaticResource Geometry/LogProfile.Database}"/>
</DrawingImage>
<DrawingImage x:Key="Image/DisableLogPatterns">
<GeometryDrawing Brush="{DynamicResource Brush/Icon}" Geometry="{StaticResource Geometry/DisableLogPatterns}"/>
</DrawingImage>
<DrawingImage x:Key="Image/DisableLogPatterns.Light">
<GeometryDrawing Brush="{DynamicResource Brush/Icon.Light}" Geometry="{StaticResource Geometry/DisableLogPatterns}"/>
</DrawingImage>
<DrawingImage x:Key="Image/DisplayableLogAnalysisResult.Checkpoint.Colored">
<GeometryDrawing Brush="{DynamicResource Brush/Icon.DisplayableLogAnalysisResult.Checkpoint}" Geometry="{DynamicResource Geometry/Icon.Flag.Outline}"/>
</DrawingImage>
Expand Down
121 changes: 114 additions & 7 deletions ULogViewer/ViewModels/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class Session : ViewModel<IULogViewerApplication>
/// </summary>
public static readonly ObservableProperty<bool> AreDisplayLogPropertiesDefinedByLogProfileProperty = ObservableProperty.Register<Session, bool>(nameof(AreDisplayLogPropertiesDefinedByLogProfile));
/// <summary>
/// Property of <see cref="AreLogPatternsDisabled"/>.
/// </summary>
public static readonly ObservableProperty<bool> AreLogPatternsDisabledProperty = ObservableProperty.Register<Session, bool>(nameof(AreLogPatternsDisabled));
/// <summary>
/// Property of <see cref="AreLogsSortedByTimestamp"/>.
/// </summary>
public static readonly ObservableProperty<bool> AreLogsSortedByTimestampProperty = ObservableProperty.Register<Session, bool>(nameof(AreLogsSortedByTimestamp));
Expand Down Expand Up @@ -147,6 +151,10 @@ class Session : ViewModel<IULogViewerApplication>
/// </summary>
public static readonly ObservableProperty<bool> HasLogFilesProperty = ObservableProperty.Register<Session, bool>(nameof(HasLogFiles));
/// <summary>
/// Property of <see cref="HasLogPatterns"/>.
/// </summary>
public static readonly ObservableProperty<bool> HasLogPatternsProperty = ObservableProperty.Register<Session, bool>(nameof(HasLogPatterns));
/// <summary>
/// Property of <see cref="HasLogProfile"/>.
/// </summary>
public static readonly ObservableProperty<bool> HasLogProfileProperty = ObservableProperty.Register<Session, bool>(nameof(HasLogProfile));
Expand Down Expand Up @@ -951,6 +959,7 @@ public Session(IULogViewerApplication app, LogProfile? initLogProfile = null) :
this.ShowAllLogsTemporarilyCommand = new Command(this.ShowAllLogsTemporarily, this.canShowAllLogsTemporarily);
this.ShowMarkedLogsTemporarilyCommand = new Command(this.ShowMarkedLogsTemporarily, this.GetValueAsObservable(HasMarkedLogsProperty));
this.StopReadingLogsCommand = new Command(this.StopReadingLogs, this.GetValueAsObservable(CanStopReadingLogsProperty));
this.ToggleLogPatternsCommand = new Command(this.ToggleLogPatterns, this.GetValueAsObservable(HasLogPatternsProperty));
this.ToggleShowingAllLogsTemporarilyCommand = new Command(this.ToggleShowingAllLogsTemporarily, this.canShowAllLogsTemporarily);
this.ToggleShowingMarkedLogsTemporarilyCommand = new Command(this.ToggleShowingMarkedLogsTemporarily, this.GetValueAsObservable(HasMarkedLogsProperty));
this.UnmarkLogsCommand = new Command<IEnumerable<DisplayableLog>>(this.UnmarkLogs, this.canMarkUnmarkLogs);
Expand Down Expand Up @@ -1540,6 +1549,12 @@ void AddLogFile(LogFileParams? param)
/// Check whether <see cref="DisplayLogProperties"/> are defined by log profile or not.
/// </summary>
public bool AreDisplayLogPropertiesDefinedByLogProfile => this.GetValue(AreDisplayLogPropertiesDefinedByLogProfileProperty);


/// <summary>
/// Check whether logs pattern defined in log profile are disabled or not.
/// </summary>
public bool AreLogPatternsDisabled => this.GetValue(AreLogPatternsDisabledProperty);


/// <summary>
Expand Down Expand Up @@ -2110,7 +2125,7 @@ bool CreateLogReader(ILogDataSource dataSource, LogReadingPrecondition precondit
it.IsContinuousReading = profile.IsContinuousReading;
it.LogLevelMap = profile.LogLevelMapForReading;
it.LogPatternMatchingMode = profile.LogPatternMatchingMode;
it.LogPatterns = profile.LogPatterns.IsNotEmpty()
it.LogPatterns = profile.LogPatterns.IsNotEmpty() && !this.GetValue(AreLogPatternsDisabledProperty)
? profile.LogPatterns
: [ new LogPattern("^(?<Message>.*)", false, false, null) ];
it.LogStringEncoding = profile.LogStringEncodingForReading;
Expand Down Expand Up @@ -2291,7 +2306,34 @@ void Deactivate(IDisposable token)
/// <summary>
/// Raised when debug message has been generated.
/// </summary>
public event EventHandler<MessageEventArgs>? DebugMessageGenerated;
public event EventHandler<MessageEventArgs>? DebugMessageGenerated;


/// <summary>
/// Disable log patterns defined in log profile.
/// </summary>
/// <returns>True if log patterns disabled successfully.</returns>
public bool DisableLogPatterns()
{
// check state
this.VerifyAccess();
this.VerifyDisposed();
if (this.GetValue(AreLogPatternsDisabledProperty))
return true;
if (!this.GetValue(HasLogPatternsProperty))
return false;
if (this.GetValue(LogProfileProperty) is not { } logProfile)
return false;

this.Logger.LogWarning("Disable log patterns defined in '{logProfile}'", logProfile.Name);

// update state
this.SetValue(AreLogPatternsDisabledProperty, true);

// reload logs
this.ScheduleReloadingLogs(true, true);
return true;
}


// Raised when group of displayable log created.
Expand Down Expand Up @@ -2492,6 +2534,33 @@ void DisposeLogReaders(bool clearLogFileInfos = false)
/// </summary>
public DateTime? EarliestLogTimestamp =>
this.GetValue(EarliestLogTimestampProperty);


/// <summary>
/// Enable log patterns defined in log profile.
/// </summary>
/// <returns>True if log patterns enabled successfully.</returns>
public bool EnableLogPatterns()
{
// check state
this.VerifyAccess();
this.VerifyDisposed();
if (!this.GetValue(AreLogPatternsDisabledProperty))
return true;
if (!this.GetValue(HasLogPatternsProperty))
return false;
if (this.GetValue(LogProfileProperty) is not { } logProfile)
return false;

this.Logger.LogWarning("Enable log patterns defined in '{logProfile}'", logProfile.Name);

// update state
this.SetValue(AreLogPatternsDisabledProperty, false);

// reload logs
this.ScheduleReloadingLogs(true, true);
return true;
}


/// <summary>
Expand Down Expand Up @@ -2641,6 +2710,12 @@ void GenerateDebugMessage(string message)
/// Check whether at least one log file was added to session or not.
/// </summary>
public bool HasLogFiles => this.GetValue(HasLogFilesProperty);


/// <summary>
/// Check whether at least one log pattern has been defined in log profile or not.
/// </summary>
public bool HasLogPatterns => this.GetValue(HasLogPatternsProperty);


/// <summary>
Expand Down Expand Up @@ -4147,6 +4222,7 @@ void ResetLogProfile()

// update state
this.ResetValue(AreDisplayLogPropertiesDefinedByLogProfileProperty);
this.ResetValue(AreLogPatternsDisabledProperty);
this.ResetValue(AreLogsSortedByTimestampProperty);
this.canResetLogProfile.Update(false);
this.canShowAllLogsTemporarily.Update(false);
Expand All @@ -4159,6 +4235,7 @@ void ResetLogProfile()
this.UpdateCanSetWorkingDirectory(null);
this.ResetValue(HasLogColorIndicatorProperty);
this.ResetValue(HasLogColorIndicatorByFileNameProperty);
this.ResetValue(HasLogPatternsProperty);
this.ResetValue(IsEmbeddedScriptLogDataSourceProviderProperty);
this.ResetValue(IsIPEndPointNeededProperty);
this.ResetValue(IsIPEndPointSupportedProperty);
Expand Down Expand Up @@ -4257,6 +4334,10 @@ public void RestoreState(JsonElement jsonState)
var isInitLogProfile = jsonState.TryGetProperty("IsInitLogProfile", out jsonValue)
&& jsonValue.ValueKind == JsonValueKind.True;
this.SetLogProfile(profile, isInitLogProfile, false);

// restore log patterns disabling state
if (jsonState.TryGetProperty(nameof(AreLogPatternsDisabled), out jsonValue) && jsonState.ValueKind == JsonValueKind.True)
this.SetValue(AreLogPatternsDisabledProperty, true);

// restore log reading precondition
if (jsonState.TryGetProperty(nameof(LastLogReadingPrecondition), out jsonValue))
Expand Down Expand Up @@ -4815,6 +4896,7 @@ void SetLogProfile(LogProfile? profile, bool isInit, bool startReadingLogs)
// update state
this.SetValue(HasLogColorIndicatorProperty, profile.ColorIndicator != LogColorIndicator.None);
this.SetValue(HasLogColorIndicatorByFileNameProperty, profile.ColorIndicator == LogColorIndicator.FileName);
this.SetValue(HasLogPatternsProperty, profile.LogPatterns.IsNotEmpty());
this.ResetValue(LastLogReadingPreconditionProperty);

// start reading logs
Expand Down Expand Up @@ -4929,6 +5011,10 @@ public void SaveState(Utf8JsonWriter jsonWriter)
if (this.isInitLogProfile)
jsonWriter.WriteBoolean("IsInitLogProfile", true);

// save log patterns disabling state
if (this.GetValue(AreLogPatternsDisabledProperty))
jsonWriter.WriteBoolean(nameof(AreLogPatternsDisabled), true);

// save logs reading parameters
if (this.logFileInfoList.IsNotEmpty())
{
Expand Down Expand Up @@ -5547,6 +5633,22 @@ void ToggleShowingMarkedLogsTemporarily()
/// </summary>
public long TotalLogsMemoryUsage =>
this.GetValue(TotalLogsMemoryUsageProperty);


// Enable or disable log patterns defined in log profile.
void ToggleLogPatterns()
{
if (this.GetValue(AreLogPatternsDisabledProperty))
this.EnableLogPatterns();
else
this.DisableLogPatterns();
}


/// <summary>
/// Command to enable or disable log patterns defined in log profile.
/// </summary>
public ICommand ToggleLogPatternsCommand { get; }


// Trigger GC if needed.
Expand Down Expand Up @@ -5833,13 +5935,18 @@ void UpdateDisplayLogProperties()
var visibleLogProperties = profile.VisibleLogProperties;
var displayLogProperties = new List<DisplayableLogProperty>();
var hasTimestamp = false;
foreach (var logProperty in visibleLogProperties)
if (!this.GetValue(AreLogPatternsDisabledProperty))
{
var displayableLogProperty = new DisplayableLogProperty(app, logProperty);
displayLogProperties.Add(displayableLogProperty);
if (!hasTimestamp)
hasTimestamp = DisplayableLog.HasDateTimeProperty(logProperty.Name);
foreach (var logProperty in visibleLogProperties)
{
var displayableLogProperty = new DisplayableLogProperty(app, logProperty);
displayLogProperties.Add(displayableLogProperty);
if (!hasTimestamp)
hasTimestamp = DisplayableLog.HasDateTimeProperty(logProperty.Name);
}
}
else if (visibleLogProperties.IsNotEmpty())
this.Logger.LogWarning("Ignore visible log properties because log patterns have been disabled");
if (displayLogProperties.IsEmpty())
{
this.ResetValue(AreDisplayLogPropertiesDefinedByLogProfileProperty);
Expand Down

0 comments on commit 2cf90ed

Please sign in to comment.