You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.0 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using IPA.Logging;
  8. namespace IPA.Logging.Printers
  9. {
  10. public class ColoredConsolePrinter : LogPrinter
  11. {
  12. Logger.LogLevel filter = Logger.LogLevel.All;
  13. public override Logger.LogLevel Filter { get => filter; set => filter = value; }
  14. ConsoleColor color = Console.ForegroundColor;
  15. public ConsoleColor Color { get => color; set => color = value; }
  16. public override void Print(Logger.Level level, DateTime time, string logName, string message)
  17. {
  18. if (((byte)level & (byte)StandardLogger.PrintFilter) == 0) return;
  19. Console.ForegroundColor = color;
  20. foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
  21. Console.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper()));
  22. Console.ResetColor();
  23. }
  24. }
  25. }