using System;
// ReSharper disable InconsistentNaming
namespace IPA.Logging
{
///
/// The logger base class. Provides the format for console logs.
///
public abstract class Logger
{
private static Logger _log;
internal static Logger log
{
get
{
if (_log == null)
_log = new StandardLogger("IPA");
return _log;
}
}
private static StandardLogger _stdout;
internal static StandardLogger stdout
{
get
{
if (_stdout == null)
_stdout = new StandardLogger("_");
return _stdout;
}
}
internal static Logger updater => log.GetChildLogger("Updater");
internal static Logger libLoader => log.GetChildLogger("LibraryLoader");
internal static Logger loader => log.GetChildLogger("Loader");
internal static Logger features => loader.GetChildLogger("Features");
internal static Logger config => log.GetChildLogger("Config");
internal static bool LogCreated => _log != null || UnityLogProvider.Logger != null;
///
/// The standard format for log messages.
///
/// the format for the standard loggers to print in
public static string LogFormat { get; protected internal set; } = "[{3} @ {2:HH:mm:ss} | {1}] {0}";
///
/// An enum specifying the level of the message. Resembles Syslog.
///
public enum Level : byte
{
///
/// No associated level. These never get shown.
///
None = 0,
///
/// A trace message. These are ignored *incredibly* early.
///
Trace = 32,
///
/// A debug message.
///
Debug = 1,
///
/// An informational message.
///
Info = 2,
///
/// A notice. More significant than Info, but less than a warning.
///
Notice = 32,
///
/// A warning message.
///
Warning = 4,
///
/// An error message.
///
Error = 8,
///
/// A critical error message.
///
Critical = 16
}
///
/// An enum providing log level filters.
///
[Flags]
public enum LogLevel : byte
{
///
/// Allow no messages through.
///
None = Level.None,
///
/// Only shows Trace messages.
///
TraceOnly = Level.Trace,
///
/// Only shows Debug messages.
///
DebugOnly = Level.Debug,
///
/// Only shows info messages.
///
InfoOnly = Level.Info,
///
/// Only shows notice messages.
///
NoticeOnly = Level.Notice,
///
/// Only shows Warning messages.
///
WarningOnly = Level.Warning,
///
/// Only shows Error messages.
///
ErrorOnly = Level.Error,
///
/// Only shows Critical messages.
///
CriticalOnly = Level.Critical,
///
/// Shows all messages error and up.
///
ErrorUp = ErrorOnly | CriticalOnly,
///
/// Shows all messages warning and up.
///
WarningUp = WarningOnly | ErrorUp,
///
/// Shows all messages Notice and up.
///
NoticeUp = WarningUp | NoticeOnly,
///
/// Shows all messages info and up.
///
InfoUp = InfoOnly | NoticeUp,
///
/// Shows all messages debug and up.
///
DebugUp = DebugOnly | InfoUp,
///
/// Shows all messages.
///
All = TraceOnly | DebugUp,
///
/// Used for when the level is undefined.
///
Undefined = Byte.MaxValue
}
///
/// A basic log function.
///
/// the level of the message
/// the message to log
public abstract void Log(Level level, string message);
///
/// A basic log function taking an exception to log.
///
/// the level of the message
/// the exception to log
public virtual void Log(Level level, Exception e) => Log(level, e.ToString());
///
/// Sends a trace message.
/// Equivalent to `Log(Level.Trace, message);`
///
///
/// the message to log
public virtual void Trace(string message) => Log(Level.Trace, message);
///
/// Sends an exception as a trace message.
/// Equivalent to `Log(Level.Trace, e);`
///
///
/// the exception to log
public virtual void Trace(Exception e) => Log(Level.Trace, e);
///
/// Sends a debug message.
/// Equivalent to `Log(Level.Debug, message);`
///
///
/// the message to log
public virtual void Debug(string message) => Log(Level.Debug, message);
///
/// Sends an exception as a debug message.
/// Equivalent to `Log(Level.Debug, e);`
///
///
/// the exception to log
public virtual void Debug(Exception e) => Log(Level.Debug, e);
///
/// Sends an info message.
/// Equivalent to `Log(Level.Info, message);`
///
///
/// the message to log
public virtual void Info(string message) => Log(Level.Info, message);
///
/// Sends an exception as an info message.
/// Equivalent to `Log(Level.Info, e);`
///
///
/// the exception to log
public virtual void Info(Exception e) => Log(Level.Info, e);
///
/// Sends a notice message.
/// Equivalent to `Log(Level.Notice, message);`
///
///
/// the message to log
public virtual void Notice(string message) => Log(Level.Notice, message);
///
/// Sends an exception as a notice message.
/// Equivalent to `Log(Level.Notice, e);`
///
///
/// the exception to log
public virtual void Notice(Exception e) => Log(Level.Notice, e);
///
/// Sends a warning message.
/// Equivalent to `Log(Level.Warning, message);`
///
///
/// the message to log
public virtual void Warn(string message) => Log(Level.Warning, message);
///
/// Sends an exception as a warning message.
/// Equivalent to `Log(Level.Warning, e);`
///
///
/// the exception to log
public virtual void Warn(Exception e) => Log(Level.Warning, e);
///
/// Sends an error message.
/// Equivalent to `Log(Level.Error, message);`
///
///
/// the message to log
public virtual void Error(string message) => Log(Level.Error, message);
///
/// Sends an exception as an error message.
/// Equivalent to `Log(Level.Error, e);`
///
///
/// the exception to log
public virtual void Error(Exception e) => Log(Level.Error, e);
///
/// Sends a critical message.
/// Equivalent to `Log(Level.Critical, message);`
///
///
/// the message to log
public virtual void Critical(string message) => Log(Level.Critical, message);
///
/// Sends an exception as a critical message.
/// Equivalent to `Log(Level.Critical, e);`
///
///
/// the exception to log
public virtual void Critical(Exception e) => Log(Level.Critical, e);
}
}