< Summary

Information
Class: Trailblazer.TrailblazerLogger
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Diagnostics/TrailblazerLogger.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 107
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_EnableDebugLogging()100%11100%
set_EnableDebugLogging(...)100%11100%
get_Channel()100%11100%
get_DebugChannel()100%11100%
get_MinimumLevel()100%11100%
set_MinimumLevel(...)100%11100%
get_LogHandler()100%11100%
set_LogHandler(...)100%11100%
get_CustomFormatter()100%11100%
set_CustomFormatter(...)100%11100%
IsEnabled(...)100%11100%
DefaultLogHandler(...)100%11100%
DefaultLogFormatter(...)100%11100%
.ctor()100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Diagnostics/TrailblazerLogger.cs

#LineLine coverage
 1//=======================================================================
 2// TrailblazerLogger.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8global using SwiftCollections.Diagnostics;
 9
 10using System;
 11
 12namespace Trailblazer;
 13
 14/// <summary>
 15/// Provides centralized diagnostics for Trailblazer runtime code.
 16/// </summary>
 17/// <remarks>
 18/// Warning and error diagnostics are controlled through <see cref="MinimumLevel"/>.
 19/// Trace-style diagnostics that were previously debug-only are additionally gated by
 20/// <see cref="EnableDebugLogging"/> so hosts can opt into verbose runtime output explicitly.
 21/// </remarks>
 22public static class TrailblazerLogger
 23{
 124    private static readonly TrailblazerDiagnosticLogger _logger = new();
 25
 26    /// <summary>
 27    /// Gets or sets a value indicating whether verbose debug diagnostics should be emitted.
 28    /// </summary>
 29    public static bool EnableDebugLogging
 30    {
 731        get => _logger.EnableDebugLogging;
 1332        set => _logger.EnableDebugLogging = value;
 33    }
 34
 35    /// <summary>
 36    /// Gets the diagnostic channel used for Trailblazer warnings and errors.
 37    /// </summary>
 3438    public static DiagnosticChannel Channel => _logger.Channel;
 39
 40    /// <summary>
 41    /// Gets the diagnostic channel used for verbose debug diagnostics.
 42    /// </summary>
 220243    public static DiagnosticChannel DebugChannel => _logger.DebugChannel;
 44
 45    /// <summary>
 46    /// Gets or sets the minimum severity required for non-debug diagnostics to be emitted.
 47    /// </summary>
 48    public static DiagnosticLevel MinimumLevel
 49    {
 850        get => _logger.MinimumLevel;
 1851        set => _logger.MinimumLevel = value;
 52    }
 53
 54    /// <summary>
 55    /// Gets or sets the delegate used to write formatted log messages.
 56    /// Assigning <see langword="null"/> restores <see cref="DefaultLogHandler"/>.
 57    /// </summary>
 58    public static Action<DiagnosticLevel, string, string> LogHandler
 59    {
 860        get => _logger.LogHandler;
 1461        set => _logger.LogHandler = value;
 62    }
 63
 64    /// <summary>
 65    /// Gets or sets the formatter used to transform log arguments into a final log entry.
 66    /// Assigning <see langword="null"/> restores <see cref="DefaultLogFormatter"/>.
 67    /// </summary>
 68    public static Func<DiagnosticLevel, string, string, string> CustomFormatter
 69    {
 670        get => _logger.CustomFormatter;
 671        set => _logger.CustomFormatter = value;
 72    }
 73
 74    /// <summary>
 75    /// Determines whether non-debug diagnostics at the specified level are currently enabled.
 76    /// </summary>
 77    /// <param name="level">The diagnostic level to evaluate.</param>
 78    /// <returns><see langword="true"/> when messages at <paramref name="level"/> will be emitted; otherwise, <see langw
 79    public static bool IsEnabled(DiagnosticLevel level)
 80    {
 481        return _logger.IsEnabled(level);
 82    }
 83
 84    /// <summary>
 85    /// The default handler for Trailblazer log messages.
 86    /// </summary>
 87    public static void DefaultLogHandler(DiagnosticLevel level, string message, string source)
 88    {
 189        _logger.DefaultLogHandler(level, message, source);
 190    }
 91
 92    /// <summary>
 93    /// Formats a Trailblazer log entry using a deterministic, source-first layout.
 94    /// </summary>
 95    public static string DefaultLogFormatter(DiagnosticLevel level, string message, string source)
 96    {
 197        return _logger.DefaultLogFormatter(level, message, source);
 98    }
 99
 100    private sealed class TrailblazerDiagnosticLogger : DiagnosticLogger
 101    {
 102        public TrailblazerDiagnosticLogger()
 1103            : base("Trailblazer")
 104        {
 1105        }
 106    }
 107}