< Summary

Information
Class: Gravitas.GravitasLogger
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Diagnostics/Logging/GravitasLogger.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 105
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/Gravitas/Gravitas/src/Gravitas/Diagnostics/Logging/GravitasLogger.cs

#LineLine coverage
 1//=======================================================================
 2// GravitasLogger.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2026–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 Gravitas;
 13
 14/// <summary>
 15/// Provides centralized diagnostics for Gravitas 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 GravitasLogger
 23{
 124    private static readonly GravitasDiagnosticLogger _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    {
 431        get => _logger.EnableDebugLogging;
 932        set => _logger.EnableDebugLogging = value;
 33    }
 34
 35    /// <summary>
 36    /// Gets the diagnostic channel used for Gravitas warnings and errors.
 37    /// </summary>
 8138    public static DiagnosticChannel Channel => _logger.Channel;
 39
 40    /// <summary>
 41    /// Gets the diagnostic channel used for verbose debug diagnostics.
 42    /// </summary>
 3243    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    {
 2350        get => _logger.MinimumLevel;
 4851        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    {
 2460        get => _logger.LogHandler;
 4761        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;
 571        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    {
 181        return _logger.IsEnabled(level);
 82    }
 83
 84    /// <summary>
 85    /// The default handler for Gravitas log messages.
 86    /// </summary>
 87    public static void DefaultLogHandler(DiagnosticLevel level, string message, string source)
 88    {
 289        _logger.DefaultLogHandler(level, message, source);
 290    }
 91
 92    /// <summary>
 93    /// Formats a Gravitas 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 GravitasDiagnosticLogger : DiagnosticLogger
 101    {
 102        public GravitasDiagnosticLogger()
 2103            : base("Gravitas") { }
 104    }
 105}