mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: add runtime loglevel switch, /xllanguage command
This commit is contained in:
parent
1df07d5ed3
commit
179787099d
4 changed files with 67 additions and 14 deletions
|
|
@ -27,6 +27,8 @@ namespace Dalamud
|
|||
|
||||
public Dictionary<int, PreferredRole> PreferredRoleReminders { get; set; }
|
||||
|
||||
public string LanguageOverride { get; set; }
|
||||
|
||||
public string LastVersion { get; set; }
|
||||
|
||||
public static DalamudConfiguration Load(string path) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ using Dalamud.Interface;
|
|||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Dalamud {
|
||||
public sealed class Dalamud : IDisposable {
|
||||
|
|
@ -50,6 +52,7 @@ namespace Dalamud {
|
|||
public readonly ClientState ClientState;
|
||||
|
||||
public readonly DalamudStartInfo StartInfo;
|
||||
private readonly LoggingLevelSwitch loggingLevelSwitch;
|
||||
|
||||
public readonly DalamudConfiguration Configuration;
|
||||
|
||||
|
|
@ -67,14 +70,19 @@ namespace Dalamud {
|
|||
|
||||
private readonly string assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString();
|
||||
|
||||
public Dalamud(DalamudStartInfo info) {
|
||||
public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch) {
|
||||
this.StartInfo = info;
|
||||
|
||||
this.localizationMgr = new Localization(this.StartInfo.WorkingDirectory);
|
||||
this.localizationMgr.SetupWithUiCulture();
|
||||
this.loggingLevelSwitch = loggingLevelSwitch;
|
||||
|
||||
this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);
|
||||
|
||||
this.localizationMgr = new Localization(this.StartInfo.WorkingDirectory);
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride)) {
|
||||
this.localizationMgr.SetupWithLangCode(this.Configuration.LanguageOverride);
|
||||
} else {
|
||||
this.localizationMgr.SetupWithUiCulture();
|
||||
}
|
||||
|
||||
this.baseDirectory = info.WorkingDirectory;
|
||||
|
||||
this.unloadSignal = new ManualResetEvent(false);
|
||||
|
|
@ -207,6 +215,18 @@ namespace Dalamud {
|
|||
this.logWindow = new DalamudLogWindow();
|
||||
this.isImguiDrawLogWindow = true;
|
||||
}
|
||||
if (ImGui.BeginMenu("Set log level..."))
|
||||
{
|
||||
foreach (var logLevel in Enum.GetValues(typeof(LogEventLevel)).Cast<LogEventLevel>()) {
|
||||
if (ImGui.MenuItem(logLevel + "##logLevelSwitch", "", this.loggingLevelSwitch.MinimumLevel == logLevel))
|
||||
{
|
||||
this.loggingLevelSwitch.MinimumLevel = logLevel;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
ImGui.Separator();
|
||||
if (ImGui.MenuItem("Open Data window"))
|
||||
{
|
||||
this.dataWindow = new DalamudDataWindow(this);
|
||||
|
|
@ -424,6 +444,11 @@ namespace Dalamud {
|
|||
this.CommandManager.AddHandler("/xlcredits", new CommandInfo(OnOpenCreditsCommand) {
|
||||
HelpMessage = Loc.Localize("DalamudCreditsHelp", "Opens the credits for dalamud.")
|
||||
});
|
||||
|
||||
this.CommandManager.AddHandler("/xllanguage", new CommandInfo(OnSetLanguageCommand)
|
||||
{
|
||||
HelpMessage = Loc.Localize("DalamudLanguageHelp", "Set the language for the in-game addon and plugins that support it.")
|
||||
});
|
||||
}
|
||||
|
||||
private void OnUnloadCommand(string command, string arguments) {
|
||||
|
|
@ -624,6 +649,19 @@ namespace Dalamud {
|
|||
this.isImguiDrawCreditsWindow = true;
|
||||
}
|
||||
|
||||
private void OnSetLanguageCommand(string command, string arguments)
|
||||
{
|
||||
if (Localization.ApplicableLangCodes.Contains(arguments.ToLower())) {
|
||||
this.localizationMgr.SetupWithLangCode(arguments.ToLower());
|
||||
this.Configuration.LanguageOverride = arguments.ToLower();
|
||||
} else {
|
||||
this.localizationMgr.SetupWithUiCulture();
|
||||
this.Configuration.LanguageOverride = null;
|
||||
}
|
||||
|
||||
this.Configuration.Save(this.StartInfo.ConfigurationPath);
|
||||
}
|
||||
|
||||
private int RouletteSlugToKey(string slug) => slug.ToLower() switch {
|
||||
"leveling" => 1,
|
||||
"506070" => 2,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using Dalamud.Interface;
|
|||
using EasyHook;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Dalamud {
|
||||
public sealed class EntryPoint : IEntryPoint {
|
||||
|
|
@ -15,7 +16,8 @@ namespace Dalamud {
|
|||
|
||||
public void Run(RemoteHooking.IContext ctx, DalamudStartInfo info) {
|
||||
// Setup logger
|
||||
Log.Logger = NewLogger(info.WorkingDirectory);
|
||||
var (logger, levelSwitch) = NewLogger(info.WorkingDirectory);
|
||||
Log.Logger = logger;
|
||||
|
||||
try {
|
||||
Log.Information("Initializing a session..");
|
||||
|
|
@ -28,7 +30,7 @@ namespace Dalamud {
|
|||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
|
||||
|
||||
using var dalamud = new Dalamud(info);
|
||||
using var dalamud = new Dalamud(info, levelSwitch);
|
||||
Log.Information("Starting a session..");
|
||||
|
||||
// Run session
|
||||
|
|
@ -44,18 +46,24 @@ namespace Dalamud {
|
|||
}
|
||||
}
|
||||
|
||||
private Logger NewLogger(string baseDirectory) {
|
||||
private (Logger logger, LoggingLevelSwitch levelSwitch) NewLogger(string baseDirectory) {
|
||||
var logPath = Path.Combine(baseDirectory, "dalamud.txt");
|
||||
|
||||
return new LoggerConfiguration()
|
||||
var levelSwitch = new LoggingLevelSwitch();
|
||||
|
||||
#if DEBUG
|
||||
levelSwitch.MinimumLevel = LogEventLevel.Verbose;
|
||||
#else
|
||||
levelSwitch.MinimumLevel = LogEventLevel.Information;
|
||||
#endif
|
||||
|
||||
var newLogger = new LoggerConfiguration()
|
||||
.WriteTo.Async(a => a.File(logPath))
|
||||
.WriteTo.EventSink()
|
||||
#if DEBUG
|
||||
.MinimumLevel.Verbose()
|
||||
#else
|
||||
.MinimumLevel.Information()
|
||||
#endif
|
||||
.MinimumLevel.ControlledBy(levelSwitch)
|
||||
.CreateLogger();
|
||||
|
||||
return (newLogger, levelSwitch);
|
||||
}
|
||||
|
||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs arg) {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ namespace Dalamud
|
|||
}
|
||||
|
||||
public void SetupWithLangCode(string langCode) {
|
||||
if (langCode.ToLower() == "en") {
|
||||
Loc.SetupWithFallbacks();
|
||||
return;
|
||||
}
|
||||
|
||||
Loc.Setup(File.ReadAllText(Path.Combine(this.workingDirectory, "UIRes", "loc", "dalamud", $"dalamud_{langCode}.json")));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue