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

v2.3.4 Update #109

Merged
merged 17 commits into from
Sep 4, 2023
Merged
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
4 changes: 4 additions & 0 deletions .config/.csharpierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"preprocessorSymbolSets": ["", "DEBUG", "DEBUG,CODE_STYLE"]
}
24 changes: 24 additions & 0 deletions .config/dotnet-tools.json
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"
]
}
}
}
22 changes: 22 additions & 0 deletions .husky/pre-commit
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
18 changes: 18 additions & 0 deletions .husky/task-runner.json
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" ]
}
]
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to Stability Matrix will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).

## v2.3.4
### Fixed
- Fixed [#108](https://github.com/LykosAI/StabilityMatrix/issues/108) - (Linux) Fixed permission error on updates [#103](https://github.com/LykosAI/StabilityMatrix/pull/103)

## v2.3.3
### Fixed
- Fixed GPU recognition for Nvidia Tesla GPUs
Expand Down
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>
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;
}
}
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();
}
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);
}
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);
}
}
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
}
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);
}
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; }
}
Loading