Skip to content

Commit

Permalink
Merge pull request #297 from betwixt-labs/remove-structure
Browse files Browse the repository at this point in the history
chore: remove structured logging
  • Loading branch information
andrewmd5 authored Jan 21, 2024
2 parents 02e4e2f + 07c92e2 commit c9830f1
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 34 deletions.
2 changes: 0 additions & 2 deletions Compiler/BebopCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Core.Exceptions;
using Core.Parser;
using Core.Generators;
using Core.Logging;
using System.IO;
using Core;

Expand Down Expand Up @@ -58,7 +57,6 @@ public static void EmitGeneratedFiles(List<GeneratedFile> generatedFiles, BebopC

public async ValueTask<GeneratedFile> BuildAsync(GeneratorConfig generatorConfig, BebopSchema schema, BebopConfig config, CancellationToken cancellationToken)
{
var (warnings, errors) = GetSchemaDiagnostics(schema, config.SupressedWarningCodes);
if (!Host.TryGetGenerator(generatorConfig.Alias, out var generator))
{
throw new CompilerException($"Could not find generator with alias '{generatorConfig.Alias}'.");
Expand Down
11 changes: 8 additions & 3 deletions Compiler/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class BuildCommand : CliCommand
{
public BuildCommand() : base(CliStrings.BuildCommand, "Build schemas into one or more target languages.")
{
SetAction(HandleCommand);
SetAction(HandleCommandAsync);
}

private async Task<int> HandleCommand(ParseResult result, CancellationToken cancellationToken)
private async Task<int> HandleCommandAsync(ParseResult result, CancellationToken cancellationToken)
{
var config = result.GetValue<BebopConfig>(CliStrings.ConfigFlag)!;

Expand Down Expand Up @@ -47,7 +47,12 @@ private async Task<int> HandleCommand(ParseResult result, CancellationToken canc
using var fs = File.Open(tempFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
using var standardInput = Console.OpenStandardInput();
// dont use async as wasi currently has threading issues
standardInput.CopyTo(fs);
#if !WASI_WASM_BUILD
await standardInput.CopyToAsync(fs, cancellationToken);
#else
standardInput.CopyTo(fs);
#endif

fs.Seek(0, SeekOrigin.Begin);
schema = compiler.ParseSchema([tempFilePath]);
}
Expand Down
1 change: 0 additions & 1 deletion Compiler/Options/DiagnosticFormatOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ private static LogFormatter Parse(string? token)
{
"enhanced" => LogFormatter.Enhanced,
"json" => LogFormatter.JSON,
"structured" => LogFormatter.Structured,
"msbuild" => LogFormatter.MSBuild,
_ => throw new ArgumentException($"Invalid diagnostic format '{token}'."),
};
Expand Down
3 changes: 1 addition & 2 deletions Compiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Text.Json;
using Core.Exceptions;
using Compiler;
using System.IO;

if (RuntimeInformation.OSArchitecture is Architecture.Wasm)
{
Expand Down Expand Up @@ -52,13 +51,13 @@
new NoWarnOption(),
new PreserveWatchOutputOption(),
},
#endif
new ConvertCommand()
{
new FromOption(),
new ToOption(),
new DryRunOption(),
},
#endif
};


Expand Down
7 changes: 6 additions & 1 deletion Compiler/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading;
using System.Threading.Tasks;
using Compiler;
using Core.Generators;
using Core.Logging;
using Core.Meta;
using Microsoft.Extensions.FileSystemGlobbing;
Expand Down Expand Up @@ -135,7 +134,9 @@ public void AddExcludeFiles(List<string> excludeFiles)
///<summary>
/// Handles the Renamed event of the FileSystemWatcher.
///</summary>
#pragma warning disable VSTHRD100 // Avoid async void methods
private async void FileRenamed(object sender, RenamedEventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
string oldFullPath = Path.GetFullPath(e.OldFullPath);
string newFullPath = Path.GetFullPath(e.FullPath);
Expand Down Expand Up @@ -219,7 +220,9 @@ private async void FileRenamed(object sender, RenamedEventArgs e)
///<summary>
/// Handles the Deleted event of the FileSystemWatcher.
///</summary>
#pragma warning disable VSTHRD100 // Avoid async void methods
private async void FileDeleted(object sender, FileSystemEventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
if (!Path.GetExtension(e.FullPath).Equals(".bop", StringComparison.InvariantCultureIgnoreCase) || IsPathExcluded(e.FullPath))
{
Expand Down Expand Up @@ -252,7 +255,9 @@ private void FileCreated(object sender, FileSystemEventArgs e)
///<summary>
/// Handles the Changed event of the FileSystemWatcher.
///</summary>
#pragma warning disable VSTHRD100 // Avoid async void methods
private async void FileChanged(object sender, FileSystemEventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
if (!Path.GetExtension(e.FullPath).Equals(".bop", StringComparison.InvariantCultureIgnoreCase) || IsPathExcluded(e.FullPath))
{
Expand Down
15 changes: 9 additions & 6 deletions Core/Logging/DiagnosticLogger.Enhanced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ private void RenderEnhancedSpanErrors(List<SpanException> exs)
foreach (var ex in group)
{
var diagnostic = new Diagnostic(ex.Severity, ex.Message, ex.ErrorCode, ex.Span);
if (diagnostic.Severity == Severity.Warning)
if (diagnostic is { Severity: Severity.Warning, Span: not null })
{
errataDiagnostic.WithLabel(new Label(fileName, GetRangeFromSpan(schemaSource, diagnostic.Span.Value), diagnostic.Message).WithColor(Color.Yellow));
}
else if (diagnostic.Severity == Severity.Error)
else if (diagnostic is { Severity: Severity.Error, Span: not null })
{
errataDiagnostic.WithLabel(new Label(fileName, GetRangeFromSpan(schemaSource, diagnostic.Span.Value), diagnostic.Message).WithColor(Color.Red));
}
Expand Down Expand Up @@ -74,15 +74,18 @@ private void RenderEnhancedException(Exception ex, int errorCode)
_err.Write(filePath);
_err.WriteLine();
}
if (ex is { StackTrace: null } and { InnerException: not null})
if (ex is { StackTrace: null } and { InnerException: not null })
{
_err.WriteLine();
_err.MarkupLine("[red bold]Inner Exception:[/]");
if (_traceEnabled) {
if (_traceEnabled)
{
_err.WriteException(ex.InnerException);
} else {
}
else
{
_err.MarkupLine($"[white]{ex.InnerException.Message}[/]");

}
}
if (_traceEnabled && !string.IsNullOrWhiteSpace(ex.StackTrace))
Expand Down
7 changes: 0 additions & 7 deletions Core/Logging/DiagnosticLogger.Format.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Core.Exceptions;
using Core.Meta;
using Core.Meta.Extensions;
using System.Text.Json.Serialization.Metadata;
using Spectre.Console;

namespace Core.Logging;

Expand All @@ -24,9 +20,6 @@ private string FormatDiagnostic(Diagnostic diagnostic)
case LogFormatter.MSBuild:
var where = span == null ? ReservedWords.CompilerName : $"{span?.FileName}({span?.StartColonString(',')})";
return $"{where} : {diagnostic.Severity.ToString().ToLowerInvariant()} BOP{diagnostic.ErrorCode}: {message}";
case LogFormatter.Structured:
where = span == null ? "" : $"Issue located in '{span?.FileName}' at {span?.StartColonString()}: ";
return $"[{DateTime.Now}][Compiler][{diagnostic.Severity}] {where}{message}";
case LogFormatter.JSON:
return JsonSerializer.Serialize(diagnostic, JsonContext.Default.Diagnostic);
case LogFormatter.Enhanced:
Expand Down
6 changes: 0 additions & 6 deletions Core/Logging/DiagnosticLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public partial class DiagnosticLogger
private static DiagnosticLogger? _instance;
private LogFormatter _formatter;
private bool _traceEnabled;
private bool _diagnosticsSupressed;
private readonly IAnsiConsole _out;
private readonly IAnsiConsole _err;
public IAnsiConsole Out => _out;
Expand Down Expand Up @@ -206,9 +205,4 @@ public void WriteErrorLine(string message)
{
_err.WriteLine(message);
}

public void SuppressDiagnostics()
{
_diagnosticsSupressed = true;
}
}
6 changes: 0 additions & 6 deletions Core/Logging/LogFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Core.Logging
/// </summary>
public enum LogFormatter : uint
{
/// <summary>
/// Data is formatted using structured logging. This is the default formatter.
/// </summary>
[Obsolete("Use Enhanced instead of Structure")]
Structured,

/// <summary>
/// Data is formatted for MSBuild comparability. View the
/// <see
Expand Down

0 comments on commit c9830f1

Please sign in to comment.