using System;
using System.IO;
namespace IPA.Logging.Printers
{
///
/// Prints log messages to the file specified by the name.
///
public class PluginSubLogPrinter : GZFilePrinter
{
///
/// Provides a filter for this specific printer.
///
public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All;
private string name;
private string mainName;
///
/// Gets the for the target file.
///
///
protected override FileInfo GetFileInfo()
{
var logsDir = new DirectoryInfo(Path.Combine("Logs", mainName, name));
logsDir.Create();
var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:yyyy.MM.dd.HH.mm}.log"));
return finfo;
}
///
/// Creates a new printer with the given name.
///
/// the name of the main logger
/// the name of the logger
public PluginSubLogPrinter(string mainname, string name)
{
this.name = name;
mainName = mainname;
}
///
/// Prints an entry to the associated file.
///
/// the of the message
/// the the message was recorded at
/// the name of the log that sent the message
/// the message to print
public override void Print(Logger.Level level, DateTime time, string logName, string message)
{
foreach (var line in removeControlCodes.Replace(message, "").Split(new[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
FileWriter.WriteLine("[{2} @ {1:HH:mm:ss}] {0}", line, time, level.ToString().ToUpper());
}
}
}