using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
}
}
internal static Logger updater => log.GetChildLogger("Updater");
internal static Logger libLoader => log.GetChildLogger("LibraryLoader");
internal static Logger loader => log.GetChildLogger("Loader");
internal static bool LogCreated => _log != null || UnityLogInterceptor._logger != null;
///
/// The standard format for log messages.
///
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 debug message.
///
Debug = 1,
///
/// An informational message.
///
Info = 2,
///
/// 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 Debug messages.
///
DebugOnly = Level.Debug,
///
/// Only shows info messages.
///
InfoOnly = Level.Info,
///
/// 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 info and up.
///
InfoUp = InfoOnly | WarningUp,
///
/// Shows all messages.
///
All = DebugOnly | InfoUp,
}
///
/// 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 exeption) => Log(level, exeption.ToString());
///
/// 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 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);
}
}