using System;
using StardewModdingAPI.Framework;
namespace StardewModdingAPI
{
/// A log writer which queues messages for output, and periodically flushes them to the console and log file.
/// Only one instance should be created.
[Obsolete("This class is internal and should not be referenced outside SMAPI. It will no longer be exposed in a future version.")]
public class LogWriter
{
/*********
** Properties
*********/
/// Manages reading and writing to the log file.
private readonly LogFileManager LogFile;
/*********
** Public methods
*********/
/// Construct an instance.
/// Manages reading and writing to the log file.
internal LogWriter(LogFileManager logFile)
{
this.WarnDeprecated();
this.LogFile = logFile;
}
/// Queue a message for output.
/// The message to log.
public void WriteToLog(string message)
{
this.WarnDeprecated();
this.WriteToLog(new LogInfo(message));
}
/// Queue a message for output.
/// The message to log.
public void WriteToLog(LogInfo message)
{
this.WarnDeprecated();
string output = $"[{message.LogTime}] {message.Message}";
if (message.PrintConsole)
{
Console.ForegroundColor = message.Colour;
Console.WriteLine(message);
Console.ForegroundColor = ConsoleColor.Gray;
}
this.LogFile.WriteLine(output);
}
/*********
** Private methods
*********/
/// Raise a deprecation warning.
private void WarnDeprecated()
{
Program.DeprecationManager.Warn($"the {nameof(LogWriter)} class", "1.0", DeprecationLevel.Info);
}
}
}