mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-31 01:08:41 +00:00
Add timestamps to logs and cleanup some code
This commit is contained in:
parent
04fb75ba15
commit
abddf5e9aa
8 changed files with 46 additions and 40 deletions
|
@ -40,12 +40,12 @@
|
|||
@{
|
||||
int size = isMobile || mini ? 50 : 100;
|
||||
bool isAdventure = Model.IsAdventurePlanet;
|
||||
string advenStyleExt = isAdventure ? "-webkit-mask-image: url(/assets/advSlotCardMask.png); -webkit-mask-size: contain; border-radius: 0%;" : "";
|
||||
string adventureStyle = isAdventure ? "-webkit-mask-image: url(/assets/advSlotCardMask.png); -webkit-mask-size: contain; border-radius: 0%;" : "";
|
||||
}
|
||||
<div>
|
||||
<img src=@(isAdventure ? "/assets/advSlotCardOverlay.png" : "/assets/slotCardOverlay.png") style="min-width: @(size)px; width: @(size)px; height: @(size)px; pointer-events: none; position: absolute; z-index: 3;">
|
||||
<img src="~/assets/slotCardBackground.png" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: absolute; z-index: 1; @(advenStyleExt)">
|
||||
<img class="cardIcon slotCardIcon" src="/gameAssets/@iconHash" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: relative; z-index: 2; @(advenStyleExt)"
|
||||
<img src="~/assets/slotCardBackground.png" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: absolute; z-index: 1; @(adventureStyle)">
|
||||
<img class="cardIcon slotCardIcon" src="/gameAssets/@iconHash" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: relative; z-index: 2; @(adventureStyle)"
|
||||
onerror="this.onerror='';this.src='/gameAssets/@ServerConfiguration.Instance.WebsiteConfiguration.MissingIconHash'">
|
||||
</div>
|
||||
<div class="cardStats">
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
@using LBPUnion.ProjectLighthouse.Extensions
|
||||
@using LBPUnion.ProjectLighthouse.Helpers
|
||||
@using LBPUnion.ProjectLighthouse.Levels
|
||||
@using LBPUnion.ProjectLighthouse.Localization.StringLists
|
||||
@using LBPUnion.ProjectLighthouse.PlayerData
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.SlotSettingsPage
|
||||
|
||||
|
@ -18,7 +17,7 @@
|
|||
|
||||
int size = isMobile ? 100 : 200;
|
||||
bool isAdventure = Model.Slot?.IsAdventurePlanet ?? false;
|
||||
string advenStyleExt = isAdventure ? "-webkit-mask-image: url(/assets/advSlotCardMask.png); -webkit-mask-size: contain; border-radius: 0%;" : "";
|
||||
string adventureStyle = isAdventure ? "-webkit-mask-image: url(/assets/advSlotCardMask.png); -webkit-mask-size: contain; border-radius: 0%;" : "";
|
||||
}
|
||||
|
||||
<script>
|
||||
|
@ -32,7 +31,7 @@ function onSubmit(){
|
|||
<div class="@(isMobile ? "" : "ui center aligned grid")">
|
||||
<div class="eight wide column">
|
||||
<div class="ui blue segment">
|
||||
<h1><i class="cog icon"></i>Slot Settings</h1>
|
||||
<h1><i class="cog icon"></i>Level Settings</h1>
|
||||
<div class="ui divider"></div>
|
||||
<form id="form" method="POST" class="ui form center aligned" action="/slot/@Model.Slot!.SlotId/settings" onsubmit="onSubmit()">
|
||||
@Html.AntiForgeryToken()
|
||||
|
@ -40,8 +39,8 @@ function onSubmit(){
|
|||
<div>
|
||||
<div>
|
||||
<img src=@(isAdventure ? "/assets/advSlotCardOverlay.png" : "/assets/slotCardOverlay.png") style="min-width: @(size)px; width: @(size)px; height: @(size)px; pointer-events: none; position: absolute; z-index: 3;">
|
||||
<img src="~/assets/slotCardBackground.png" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: absolute; z-index: 1; @(advenStyleExt)">
|
||||
<img id="slotIcon" class="cardIcon slotCardIcon" src="/gameAssets/@Model.Slot.IconHash" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: relative; z-index: 2; @(advenStyleExt)"
|
||||
<img src="~/assets/slotCardBackground.png" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: absolute; z-index: 1; @(adventureStyle)">
|
||||
<img id="slotIcon" class="cardIcon slotCardIcon" src="/gameAssets/@Model.Slot.IconHash" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: relative; z-index: 2; @(adventureStyle)"
|
||||
onerror="this.onerror='';this.src='/gameAssets/@ServerConfiguration.Instance.WebsiteConfiguration.MissingIconHash'">
|
||||
</div>
|
||||
<div class="ui fitted divider hidden"></div>
|
||||
|
@ -54,7 +53,7 @@ function onSubmit(){
|
|||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label style="text-align: left" for="name">@Model.Translate(GeneralStrings.Username)</label>
|
||||
<label style="text-align: left" for="name">Name</label>
|
||||
<input type="text" name="name" id="name" value="@HttpUtility.HtmlDecode(Model.Slot.Name)" placeholder="Name">
|
||||
</div>
|
||||
<div class="field">
|
||||
|
|
|
@ -6,7 +6,7 @@ using LBPUnion.ProjectLighthouse.Helpers;
|
|||
|
||||
namespace LBPUnion.ProjectLighthouse.Administration.Maintenance.Commands
|
||||
{
|
||||
public class CreateAPIKeyCommand : ICommand
|
||||
public class CreateApiKeyCommand : ICommand
|
||||
{
|
||||
public string Name() => "Create API Key";
|
||||
public string[] Aliases() => new[] { "createAPIKey", };
|
||||
|
@ -15,8 +15,7 @@ namespace LBPUnion.ProjectLighthouse.Administration.Maintenance.Commands
|
|||
|
||||
public async Task Run(string[] args, Logger logger)
|
||||
{
|
||||
APIKey key = new();
|
||||
key.Description = args[0];
|
||||
APIKey key = new() { Description = args[0], };
|
||||
if (string.IsNullOrWhiteSpace(key.Description))
|
||||
{
|
||||
key.Description = "<no description specified>";
|
||||
|
|
|
@ -34,7 +34,9 @@ public static class InfluxHelper
|
|||
using WriteApi writeApi = Client.GetWriteApi();
|
||||
PointData point = PointData.Measurement("lighthouse")
|
||||
.Field("playerCount", await StatisticsHelper.RecentMatches(database))
|
||||
.Field("slotCount", await StatisticsHelper.SlotCount(database));
|
||||
.Field("slotCount", await StatisticsHelper.SlotCount(database))
|
||||
.Field("userCount", await StatisticsHelper.UserCount(database))
|
||||
.Field("photoCount", await StatisticsHelper.PhotoCount(database));
|
||||
|
||||
foreach (GameVersion gameVersion in gameVersions)
|
||||
{
|
||||
|
|
|
@ -23,11 +23,11 @@ public class Logger
|
|||
|
||||
public void AddLogger(ILogger logger)
|
||||
{
|
||||
loggers.Add(logger);
|
||||
LogDebug("Initialized " + logger.GetType().Name, LogArea.Logger);
|
||||
this.loggers.Add(logger);
|
||||
this.LogDebug("Initialized " + logger.GetType().Name, LogArea.Logger);
|
||||
}
|
||||
|
||||
private LogTrace getTrace(int extraTraceLines = 0)
|
||||
private static LogTrace getTrace(int extraTraceLines = 0)
|
||||
{
|
||||
const int depth = 5;
|
||||
const int skipDepth = depth - 2;
|
||||
|
@ -79,7 +79,7 @@ public class Logger
|
|||
/// <param name="logLine">The logLine to send to the queue.</param>
|
||||
private void queueLog(LogLine logLine)
|
||||
{
|
||||
logQueue.Enqueue(logLine);
|
||||
this.logQueue.Enqueue(logLine);
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "FunctionNeverReturns")]
|
||||
|
@ -91,7 +91,7 @@ public class Logger
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
bool logged = queueLoop();
|
||||
bool logged = this.queueLoop();
|
||||
Thread.Sleep(logged ? 10 : 100);
|
||||
// We wait 100ms if we dont log since it's less likely that the program logged again.
|
||||
// If we did log, wait 10ms before looping again.
|
||||
|
@ -102,17 +102,17 @@ public class Logger
|
|||
);
|
||||
|
||||
// Flush the log queue when we're exiting.
|
||||
AppDomain.CurrentDomain.UnhandledException += Flush;
|
||||
AppDomain.CurrentDomain.ProcessExit += Flush;
|
||||
AppDomain.CurrentDomain.UnhandledException += this.Flush;
|
||||
AppDomain.CurrentDomain.ProcessExit += this.Flush;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs everything in the queue to all loggers immediately.
|
||||
/// This is a helper function to allow for this function to be easily added to events.
|
||||
/// </summary>
|
||||
public void Flush(object? _, EventArgs __)
|
||||
private void Flush(object? _, EventArgs __)
|
||||
{
|
||||
Flush();
|
||||
this.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -120,9 +120,9 @@ public class Logger
|
|||
/// </summary>
|
||||
public void Flush()
|
||||
{
|
||||
while (logQueue.TryDequeue(out LogLine line))
|
||||
while (this.logQueue.TryDequeue(out LogLine line))
|
||||
{
|
||||
foreach (ILogger logger in loggers)
|
||||
foreach (ILogger logger in this.loggers)
|
||||
{
|
||||
logger.Log(line);
|
||||
}
|
||||
|
@ -135,18 +135,14 @@ public class Logger
|
|||
/// <returns></returns>
|
||||
private bool queueLoop()
|
||||
{
|
||||
bool logged = false;
|
||||
if (logQueue.TryDequeue(out LogLine line))
|
||||
{
|
||||
logged = true;
|
||||
if (!this.logQueue.TryDequeue(out LogLine line)) return false;
|
||||
|
||||
foreach (ILogger logger in loggers)
|
||||
{
|
||||
logger.Log(line);
|
||||
}
|
||||
foreach (ILogger logger in this.loggers)
|
||||
{
|
||||
logger.Log(line);
|
||||
}
|
||||
|
||||
return logged;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -212,7 +208,7 @@ public class Logger
|
|||
|
||||
public void Log(string text, string area, LogLevel level, int extraTraceLines = 0)
|
||||
{
|
||||
queueLog(new LogLine
|
||||
this.queueLog(new LogLine
|
||||
{
|
||||
Level = level,
|
||||
Message = text,
|
||||
|
|
|
@ -10,7 +10,7 @@ public class AspNetToLighthouseLogger : Microsoft.Extensions.Logging.ILogger
|
|||
public IDisposable BeginScope<TState>(TState state) => NullScope.Instance;
|
||||
public bool IsEnabled(AspLogLevel logLevel) => true;
|
||||
|
||||
public string Category { get; init; }
|
||||
private string Category { get; init; }
|
||||
|
||||
public AspNetToLighthouseLogger(string category)
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ public class AspNetToLighthouseLogger : Microsoft.Extensions.Logging.ILogger
|
|||
{
|
||||
LogLevel level = logLevel.ToLighthouseLevel();
|
||||
|
||||
Logger.Instance.Log(state.ToString(), this.Category, level, 4);
|
||||
Logger.Instance.Log(state.ToString() ?? string.Empty, this.Category, level, 4);
|
||||
|
||||
if (exception == null) return;
|
||||
|
||||
|
|
|
@ -14,6 +14,15 @@ public class ConsoleLogger : ILogger
|
|||
// The following is scuffed.
|
||||
// Beware~
|
||||
|
||||
string time = DateTime.Now.ToString("MM/dd/yyyy-HH:mm:ss.fff");
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write('[');
|
||||
Console.ForegroundColor = logLine.Level.ToColor();
|
||||
Console.Write(time);
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write(']');
|
||||
Console.Write(' ');
|
||||
|
||||
// Write the level! [Success]
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write('[');
|
||||
|
@ -42,7 +51,8 @@ public class ConsoleLogger : ILogger
|
|||
Console.Write(logLine.Trace.Section);
|
||||
}
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write("> ");
|
||||
Console.Write('>');
|
||||
Console.Write(' ');
|
||||
Console.ForegroundColor = oldForegroundColor;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ public class FileLogger : ILogger
|
|||
public void Log(LogLine line)
|
||||
{
|
||||
FileHelper.EnsureDirectoryCreated(logsDirectory);
|
||||
|
||||
string contentFile = $"[{ServerStatics.ServerType}] [{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
|
||||
string contentAll = $"[{ServerStatics.ServerType}] [{line.Area}:{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
|
||||
string time = DateTime.Now.ToString("MM/dd/yyyy-HH:mm:ss.fff");
|
||||
string contentFile = $"[{time}] [{ServerStatics.ServerType}] [{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
|
||||
string contentAll = $"[{time}] [{ServerStatics.ServerType}] [{line.Area}:{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
|
||||
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue