-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from LykosAI/main
- Loading branch information
Showing
44 changed files
with
1,341 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"printWidth": 120, | ||
"preprocessorSymbolSets": ["", "DEBUG", "DEBUG,CODE_STYLE"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"husky": { | ||
"version": "0.6.0", | ||
"commands": [ | ||
"husky" | ||
] | ||
}, | ||
"xamlstyler.console": { | ||
"version": "3.2206.4", | ||
"commands": [ | ||
"xstyler" | ||
] | ||
}, | ||
"csharpier": { | ||
"version": "0.25.0", | ||
"commands": [ | ||
"dotnet-csharpier" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
## husky task runner examples ------------------- | ||
## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky' | ||
|
||
## run all tasks | ||
#husky run | ||
|
||
### run all tasks with group: 'group-name' | ||
dotnet husky run --group "pre-commit" | ||
|
||
## run task with name: 'task-name' | ||
#husky run --name task-name | ||
|
||
## pass hook arguments to task | ||
#husky run --args "$1" "$2" | ||
|
||
## or put your custom commands ------------------- | ||
#echo 'Husky.Net is awesome!' | ||
|
||
#dotnet husky run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"tasks": [ | ||
{ | ||
"name": "Run csharpier", | ||
"group": "pre-commit", | ||
"command": "dotnet", | ||
"args": [ "csharpier", "${staged}" ], | ||
"include": [ "**/*.cs" ] | ||
}, | ||
{ | ||
"name": "Run xamlstyler", | ||
"group": "pre-commit", | ||
"command": "dotnet", | ||
"args": [ "xstyler", "${staged}" ], | ||
"include": [ "**/*.axaml" ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
StabilityMatrix.Avalonia.Diagnostics/LogViewer/Controls/LogViewerControl.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<UserControl x:Class="StabilityMatrix.Avalonia.Diagnostics.LogViewer.Controls.LogViewerControl" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:converters="clr-namespace:StabilityMatrix.Avalonia.Diagnostics.LogViewer.Converters" | ||
xmlns:logging="clr-namespace:StabilityMatrix.Avalonia.Diagnostics.LogViewer.Core.Logging" | ||
x:CompileBindings="True" | ||
x:DataType="logging:ILogDataStoreImpl" | ||
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" > | ||
|
||
<Grid RowDefinitions="*,Auto"> | ||
<Grid.Resources> | ||
<converters:ChangeColorTypeConverter x:Key="ColorConverter" /> | ||
<converters:EventIdConverter x:Key="EventIdConverter"/> | ||
<SolidColorBrush x:Key="ColorBlack">Black</SolidColorBrush> | ||
<SolidColorBrush x:Key="ColorTransparent">Transparent</SolidColorBrush> | ||
</Grid.Resources> | ||
<Grid.Styles> | ||
<Style Selector="DataGridRow"> | ||
<Setter Property="Padding" Value="0" /> | ||
<Setter Property="Foreground" | ||
x:DataType="logging:LogModel" | ||
Value="{Binding Color.Foreground, | ||
FallbackValue=White, | ||
Converter={StaticResource ColorConverter}, ConverterParameter={StaticResource ColorBlack}}" /> | ||
<Setter Property="Background" | ||
x:DataType="logging:LogModel" | ||
Value="{Binding Color.Background, | ||
FallbackValue=Black, | ||
Converter={StaticResource ColorConverter}, ConverterParameter={StaticResource ColorTransparent}}" /> | ||
</Style> | ||
<Style Selector="DataGridCell.size"> | ||
<Setter Property="FontSize" Value="13" /> | ||
<Setter Property="Padding" Value="0" /> | ||
</Style> | ||
</Grid.Styles> | ||
<DataGrid x:Name="MyDataGrid" | ||
ItemsSource="{Binding DataStore.Entries}" AutoGenerateColumns="False" | ||
CanUserResizeColumns="True" | ||
CanUserReorderColumns="True" | ||
CanUserSortColumns="False" | ||
LayoutUpdated="OnLayoutUpdated"> | ||
|
||
<DataGrid.Styles> | ||
<Style Selector="TextBlock"> | ||
<Setter Property="TextWrapping" Value="WrapWithOverflow" /> | ||
</Style> | ||
</DataGrid.Styles> | ||
|
||
<DataGrid.Columns> | ||
<DataGridTextColumn CellStyleClasses="size" Header="Time" Width="Auto" Binding="{Binding Timestamp}" IsVisible="{Binding #IsTimestampVisible.IsChecked}"/> | ||
<DataGridTextColumn CellStyleClasses="size" Header="Level" Width="Auto" Binding="{Binding LogLevel}" /> | ||
<!--<DataGridTextColumn CellStyleClasses="size" Header="Event Id" Width="120" Binding="{Binding EventId, Converter={StaticResource EventIdConverter}}" />--> | ||
<DataGridTextColumn CellStyleClasses="size" Header="Callsite" Width="Auto" Binding="{Binding LoggerDisplayName}" /> | ||
<DataGridTextColumn CellStyleClasses="size" Header="State" Width="*" Binding="{Binding State}" /> | ||
<DataGridTextColumn CellStyleClasses="size" Header="Exception" Width="Auto" Binding="{Binding Exception}" /> | ||
</DataGrid.Columns> | ||
</DataGrid> | ||
|
||
<StackPanel Grid.Row="1" Margin="20 10" Orientation="Horizontal"> | ||
<CheckBox x:Name="CanAutoScroll" | ||
FontSize="11" | ||
Content="Auto Scroll log" | ||
IsChecked="True"/> | ||
<CheckBox x:Name="IsTimestampVisible" | ||
FontSize="11" | ||
Content="Show Timestamp"/> | ||
</StackPanel> | ||
|
||
|
||
</Grid> | ||
|
||
</UserControl> |
52 changes: 52 additions & 0 deletions
52
StabilityMatrix.Avalonia.Diagnostics/LogViewer/Controls/LogViewerControl.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Specialized; | ||
using Avalonia.Controls; | ||
using Avalonia.LogicalTree; | ||
using Avalonia.Threading; | ||
using StabilityMatrix.Avalonia.Diagnostics.LogViewer.Core.Logging; | ||
|
||
namespace StabilityMatrix.Avalonia.Diagnostics.LogViewer.Controls; | ||
|
||
public partial class LogViewerControl : UserControl | ||
{ | ||
public LogViewerControl() | ||
=> InitializeComponent(); | ||
|
||
private ILogDataStoreImpl? vm; | ||
private LogModel? item; | ||
|
||
protected override void OnDataContextChanged(EventArgs e) | ||
{ | ||
base.OnDataContextChanged(e); | ||
|
||
if (DataContext is null) | ||
return; | ||
|
||
vm = (ILogDataStoreImpl)DataContext; | ||
vm.DataStore.Entries.CollectionChanged += OnCollectionChanged; | ||
} | ||
|
||
private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) | ||
{ | ||
Dispatcher.UIThread.Post(() => | ||
{ | ||
item = MyDataGrid.ItemsSource.Cast<LogModel>().LastOrDefault(); | ||
}); | ||
} | ||
|
||
protected void OnLayoutUpdated(object? sender, EventArgs e) | ||
{ | ||
if (CanAutoScroll.IsChecked != true || item is null) | ||
return; | ||
|
||
MyDataGrid.ScrollIntoView(item, null); | ||
item = null; | ||
} | ||
|
||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) | ||
{ | ||
base.OnDetachedFromLogicalTree(e); | ||
|
||
if (vm is null) return; | ||
vm.DataStore.Entries.CollectionChanged -= OnCollectionChanged; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
StabilityMatrix.Avalonia.Diagnostics/LogViewer/Converters/ChangeColorTypeConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Globalization; | ||
using Avalonia.Data.Converters; | ||
using Avalonia.Media; | ||
using SysDrawColor = System.Drawing.Color; | ||
|
||
namespace StabilityMatrix.Avalonia.Diagnostics.LogViewer.Converters; | ||
|
||
public class ChangeColorTypeConverter : IValueConverter | ||
{ | ||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
if (value is null) | ||
return new SolidColorBrush((Color)(parameter ?? Colors.Black)); | ||
|
||
var sysDrawColor = (SysDrawColor)value!; | ||
return new SolidColorBrush(Color.FromArgb( | ||
sysDrawColor.A, | ||
sysDrawColor.R, | ||
sysDrawColor.G, | ||
sysDrawColor.B)); | ||
} | ||
|
||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
=> throw new NotImplementedException(); | ||
} |
22 changes: 22 additions & 0 deletions
22
StabilityMatrix.Avalonia.Diagnostics/LogViewer/Converters/EventIdConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Globalization; | ||
using Avalonia.Data.Converters; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace StabilityMatrix.Avalonia.Diagnostics.LogViewer.Converters; | ||
|
||
public class EventIdConverter : IValueConverter | ||
{ | ||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
if (value is null) | ||
return "0"; | ||
|
||
var eventId = (EventId)value; | ||
|
||
return eventId.ToString(); | ||
} | ||
|
||
// If not implemented, an error is thrown | ||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
=> new EventId(0, value?.ToString() ?? string.Empty); | ||
} |
55 changes: 55 additions & 0 deletions
55
StabilityMatrix.Avalonia.Diagnostics/LogViewer/Core/Extensions/LoggerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace StabilityMatrix.Avalonia.Diagnostics.LogViewer.Core.Extensions; | ||
|
||
public static class LoggerExtensions | ||
{ | ||
public static void Emit(this ILogger logger, EventId eventId, | ||
LogLevel logLevel, string message, Exception? exception = null, params object?[] args) | ||
{ | ||
if (logger is null) | ||
return; | ||
|
||
//if (!logger.IsEnabled(logLevel)) | ||
// return; | ||
|
||
switch (logLevel) | ||
{ | ||
case LogLevel.Trace: | ||
logger.LogTrace(eventId, message, args); | ||
break; | ||
|
||
case LogLevel.Debug: | ||
logger.LogDebug(eventId, message, args); | ||
break; | ||
|
||
case LogLevel.Information: | ||
logger.LogInformation(eventId, message, args); | ||
break; | ||
|
||
case LogLevel.Warning: | ||
logger.LogWarning(eventId, exception, message, args); | ||
break; | ||
|
||
case LogLevel.Error: | ||
logger.LogError(eventId, exception, message, args); | ||
break; | ||
|
||
case LogLevel.Critical: | ||
logger.LogCritical(eventId, exception, message, args); | ||
break; | ||
} | ||
} | ||
|
||
public static void TestPattern(this ILogger logger, EventId eventId) | ||
{ | ||
var exception = new Exception("Test Error Message"); | ||
|
||
logger.Emit(eventId, LogLevel.Trace, "Trace Test Pattern"); | ||
logger.Emit(eventId, LogLevel.Debug, "Debug Test Pattern"); | ||
logger.Emit(eventId, LogLevel.Information, "Information Test Pattern"); | ||
logger.Emit(eventId, LogLevel.Warning, "Warning Test Pattern"); | ||
logger.Emit(eventId, LogLevel.Error, "Error Test Pattern", exception); | ||
logger.Emit(eventId, LogLevel.Critical, "Critical Test Pattern", exception); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
StabilityMatrix.Avalonia.Diagnostics/LogViewer/Core/Logging/DataStoreLoggerConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Drawing; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace StabilityMatrix.Avalonia.Diagnostics.LogViewer.Core.Logging; | ||
|
||
public class DataStoreLoggerConfiguration | ||
{ | ||
#region Properties | ||
|
||
public EventId EventId { get; set; } | ||
|
||
public Dictionary<LogLevel, LogEntryColor> Colors { get; } = new() | ||
{ | ||
[LogLevel.Trace] = new LogEntryColor | ||
{ | ||
Foreground = Color.DarkGray | ||
}, | ||
[LogLevel.Debug] = new LogEntryColor | ||
{ | ||
Foreground = Color.Gray | ||
}, | ||
[LogLevel.Information] = new LogEntryColor | ||
{ | ||
Foreground = Color.WhiteSmoke, | ||
}, | ||
[LogLevel.Warning] = new LogEntryColor | ||
{ | ||
Foreground = Color.Orange | ||
}, | ||
[LogLevel.Error] = new LogEntryColor | ||
{ | ||
Foreground = Color.White, | ||
Background = Color.OrangeRed | ||
}, | ||
[LogLevel.Critical] = new LogEntryColor | ||
{ | ||
Foreground = Color.White, | ||
Background = Color.Red | ||
}, | ||
[LogLevel.None] = new LogEntryColor | ||
{ | ||
Foreground = Color.Magenta | ||
} | ||
}; | ||
|
||
#endregion | ||
} |
9 changes: 9 additions & 0 deletions
9
StabilityMatrix.Avalonia.Diagnostics/LogViewer/Core/Logging/ILogDataStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace StabilityMatrix.Avalonia.Diagnostics.LogViewer.Core.Logging; | ||
|
||
public interface ILogDataStore | ||
{ | ||
ObservableCollection<LogModel> Entries { get; } | ||
void AddEntry(LogModel logModel); | ||
} |
6 changes: 6 additions & 0 deletions
6
StabilityMatrix.Avalonia.Diagnostics/LogViewer/Core/Logging/ILogDataStoreImpl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace StabilityMatrix.Avalonia.Diagnostics.LogViewer.Core.Logging; | ||
|
||
public interface ILogDataStoreImpl | ||
{ | ||
public ILogDataStore DataStore { get; } | ||
} |
Oops, something went wrong.