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

More flexible logging #160

Open
wants to merge 6 commits into
base: debug
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions Photino.NET/DefaultPhotinoLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace PhotinoNET;

internal sealed class DefaultPhotinoLogger : IPhotinoLogger
{
private readonly PhotinoWindow _window;

public DefaultPhotinoLogger(PhotinoWindow window)
{
_window = window;
}

public void Log(int verbosity, Exception exception, string message)
{
if (_window.LogVerbosity < verbosity)
return;

if (exception is not null)
message = $"***\n{exception.Message}\n{exception.StackTrace}\n{message}";

Console.WriteLine($"Photino.NET: \"{_window.Title ?? "PhotinoWindow"}\"{message}");
}
}
17 changes: 17 additions & 0 deletions Photino.NET/IPhotinoLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace PhotinoNET;

/// <summary>
/// Defines an interface for implementing logging functionality.
/// </summary>
public interface IPhotinoLogger
{
/// <summary>
/// Logs a message with the specified verbosity level, exception information, and a custom message.
/// </summary>
/// <param name="verbosity">The verbosity level of the log entry.</param>
/// <param name="exception">The exception to log. Can be null if not applicable.</param>
/// <param name="message">The custom message to log.</param>
void Log(int verbosity, Exception exception, string message);
}
20 changes: 20 additions & 0 deletions Photino.NET/LogVerbosity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace PhotinoNET;

/// <summary>
/// Defines a static class for specifying log verbosity levels in the Photino window.
/// This class provides predefined constants to easily set and understand the desired level of logging detail.
/// </summary>
public static class LogVerbosity
{
/// <summary>Logs only critical errors. Value: 0.</summary>
public static readonly int Critical = 0;

/// <summary>Logs critical errors and warnings. Value: 1.</summary>
public static readonly int Warning = 1;

/// <summary>Logs detailed information, including errors and warnings. Value: 2.</summary>
public static readonly int Verbose = 2;

/// <summary>Logs all details for debugging purposes, including verbose output. Value: 3.</summary>
public static readonly int Debug = 3;
}
Loading