using System;
namespace BepInEx.Logging
{
///
/// The level, or severity of a log entry.
///
[Flags]
public enum LogLevel
{
///
/// No level selected.
///
None = 0,
///
/// A fatal error has occurred, which cannot be recovered from.
///
Fatal = 1,
///
/// An error has occured, but can be recovered from.
///
Error = 2,
///
/// A warning has been produced, but does not necessarily mean that something wrong has happened.
///
Warning = 4,
///
/// An important message that should be displayed to the user.
///
Message = 8,
///
/// A message of low importance.
///
Info = 16,
///
/// A message that would likely only interest a developer.
///
Debug = 32,
///
/// All log levels.
///
All = Fatal | Error | Warning | Message | Info | Debug
}
public static class LogLevelExtensions
{
///
/// Gets the highest log level when there could potentially be multiple levels provided.
///
/// The log level(s).
/// The highest log level supplied.
public static LogLevel GetHighestLevel(this LogLevel levels)
{
var enums = Enum.GetValues(typeof(LogLevel));
Array.Sort(enums);
foreach (LogLevel e in enums)
{
if ((levels & e) != LogLevel.None)
return e;
}
return LogLevel.None;
}
///
/// Returns a translation of a log level to it's associated console colour.
///
/// The log level(s).
/// A console color associated with the highest log level supplied.
public static ConsoleColor GetConsoleColor(this LogLevel level)
{
level = GetHighestLevel(level);
switch (level)
{
case LogLevel.Fatal:
return ConsoleColor.Red;
case LogLevel.Error:
return ConsoleColor.DarkRed;
case LogLevel.Warning:
return ConsoleColor.Yellow;
case LogLevel.Message:
return ConsoleColor.White;
case LogLevel.Info:
default:
return ConsoleColor.Gray;
case LogLevel.Debug:
return ConsoleColor.DarkGray;
}
}
}
}