Add timestamps to logs and cleanup some code

This commit is contained in:
Slendy 2022-10-01 16:28:52 -05:00
commit abddf5e9aa
No known key found for this signature in database
GPG key ID: 7288D68361B91428
8 changed files with 46 additions and 40 deletions

View file

@ -40,12 +40,12 @@
@{ @{
int size = isMobile || mini ? 50 : 100; int size = isMobile || mini ? 50 : 100;
bool isAdventure = Model.IsAdventurePlanet; 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> <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=@(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 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; @(advenStyleExt)" <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'"> onerror="this.onerror='';this.src='/gameAssets/@ServerConfiguration.Instance.WebsiteConfiguration.MissingIconHash'">
</div> </div>
<div class="cardStats"> <div class="cardStats">

View file

@ -4,7 +4,6 @@
@using LBPUnion.ProjectLighthouse.Extensions @using LBPUnion.ProjectLighthouse.Extensions
@using LBPUnion.ProjectLighthouse.Helpers @using LBPUnion.ProjectLighthouse.Helpers
@using LBPUnion.ProjectLighthouse.Levels @using LBPUnion.ProjectLighthouse.Levels
@using LBPUnion.ProjectLighthouse.Localization.StringLists
@using LBPUnion.ProjectLighthouse.PlayerData @using LBPUnion.ProjectLighthouse.PlayerData
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.SlotSettingsPage @model LBPUnion.ProjectLighthouse.Servers.Website.Pages.SlotSettingsPage
@ -18,7 +17,7 @@
int size = isMobile ? 100 : 200; int size = isMobile ? 100 : 200;
bool isAdventure = Model.Slot?.IsAdventurePlanet ?? false; 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> <script>
@ -32,7 +31,7 @@ function onSubmit(){
<div class="@(isMobile ? "" : "ui center aligned grid")"> <div class="@(isMobile ? "" : "ui center aligned grid")">
<div class="eight wide column"> <div class="eight wide column">
<div class="ui blue segment"> <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> <div class="ui divider"></div>
<form id="form" method="POST" class="ui form center aligned" action="/slot/@Model.Slot!.SlotId/settings" onsubmit="onSubmit()"> <form id="form" method="POST" class="ui form center aligned" action="/slot/@Model.Slot!.SlotId/settings" onsubmit="onSubmit()">
@Html.AntiForgeryToken() @Html.AntiForgeryToken()
@ -40,8 +39,8 @@ function onSubmit(){
<div> <div>
<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=@(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 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; @(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; @(adventureStyle)"
onerror="this.onerror='';this.src='/gameAssets/@ServerConfiguration.Instance.WebsiteConfiguration.MissingIconHash'"> onerror="this.onerror='';this.src='/gameAssets/@ServerConfiguration.Instance.WebsiteConfiguration.MissingIconHash'">
</div> </div>
<div class="ui fitted divider hidden"></div> <div class="ui fitted divider hidden"></div>
@ -54,7 +53,7 @@ function onSubmit(){
</div> </div>
</div> </div>
<div class="field"> <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"> <input type="text" name="name" id="name" value="@HttpUtility.HtmlDecode(Model.Slot.Name)" placeholder="Name">
</div> </div>
<div class="field"> <div class="field">

View file

@ -6,7 +6,7 @@ using LBPUnion.ProjectLighthouse.Helpers;
namespace LBPUnion.ProjectLighthouse.Administration.Maintenance.Commands namespace LBPUnion.ProjectLighthouse.Administration.Maintenance.Commands
{ {
public class CreateAPIKeyCommand : ICommand public class CreateApiKeyCommand : ICommand
{ {
public string Name() => "Create API Key"; public string Name() => "Create API Key";
public string[] Aliases() => new[] { "createAPIKey", }; public string[] Aliases() => new[] { "createAPIKey", };
@ -15,8 +15,7 @@ namespace LBPUnion.ProjectLighthouse.Administration.Maintenance.Commands
public async Task Run(string[] args, Logger logger) public async Task Run(string[] args, Logger logger)
{ {
APIKey key = new(); APIKey key = new() { Description = args[0], };
key.Description = args[0];
if (string.IsNullOrWhiteSpace(key.Description)) if (string.IsNullOrWhiteSpace(key.Description))
{ {
key.Description = "<no description specified>"; key.Description = "<no description specified>";

View file

@ -34,7 +34,9 @@ public static class InfluxHelper
using WriteApi writeApi = Client.GetWriteApi(); using WriteApi writeApi = Client.GetWriteApi();
PointData point = PointData.Measurement("lighthouse") PointData point = PointData.Measurement("lighthouse")
.Field("playerCount", await StatisticsHelper.RecentMatches(database)) .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) foreach (GameVersion gameVersion in gameVersions)
{ {

View file

@ -23,11 +23,11 @@ public class Logger
public void AddLogger(ILogger logger) public void AddLogger(ILogger logger)
{ {
loggers.Add(logger); this.loggers.Add(logger);
LogDebug("Initialized " + logger.GetType().Name, LogArea.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 depth = 5;
const int skipDepth = depth - 2; const int skipDepth = depth - 2;
@ -79,7 +79,7 @@ public class Logger
/// <param name="logLine">The logLine to send to the queue.</param> /// <param name="logLine">The logLine to send to the queue.</param>
private void queueLog(LogLine logLine) private void queueLog(LogLine logLine)
{ {
logQueue.Enqueue(logLine); this.logQueue.Enqueue(logLine);
} }
[SuppressMessage("ReSharper", "FunctionNeverReturns")] [SuppressMessage("ReSharper", "FunctionNeverReturns")]
@ -91,7 +91,7 @@ public class Logger
{ {
while (true) while (true)
{ {
bool logged = queueLoop(); bool logged = this.queueLoop();
Thread.Sleep(logged ? 10 : 100); Thread.Sleep(logged ? 10 : 100);
// We wait 100ms if we dont log since it's less likely that the program logged again. // 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. // If we did log, wait 10ms before looping again.
@ -102,17 +102,17 @@ public class Logger
); );
// Flush the log queue when we're exiting. // Flush the log queue when we're exiting.
AppDomain.CurrentDomain.UnhandledException += Flush; AppDomain.CurrentDomain.UnhandledException += this.Flush;
AppDomain.CurrentDomain.ProcessExit += Flush; AppDomain.CurrentDomain.ProcessExit += this.Flush;
} }
/// <summary> /// <summary>
/// Logs everything in the queue to all loggers immediately. /// 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. /// This is a helper function to allow for this function to be easily added to events.
/// </summary> /// </summary>
public void Flush(object? _, EventArgs __) private void Flush(object? _, EventArgs __)
{ {
Flush(); this.Flush();
} }
/// <summary> /// <summary>
@ -120,9 +120,9 @@ public class Logger
/// </summary> /// </summary>
public void Flush() 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); logger.Log(line);
} }
@ -135,18 +135,14 @@ public class Logger
/// <returns></returns> /// <returns></returns>
private bool queueLoop() private bool queueLoop()
{ {
bool logged = false; if (!this.logQueue.TryDequeue(out LogLine line)) return false;
if (logQueue.TryDequeue(out LogLine line))
{
logged = true;
foreach (ILogger logger in loggers) foreach (ILogger logger in this.loggers)
{ {
logger.Log(line); logger.Log(line);
}
} }
return logged; return true;
} }
#endregion #endregion
@ -212,7 +208,7 @@ public class Logger
public void Log(string text, string area, LogLevel level, int extraTraceLines = 0) public void Log(string text, string area, LogLevel level, int extraTraceLines = 0)
{ {
queueLog(new LogLine this.queueLog(new LogLine
{ {
Level = level, Level = level,
Message = text, Message = text,

View file

@ -10,7 +10,7 @@ public class AspNetToLighthouseLogger : Microsoft.Extensions.Logging.ILogger
public IDisposable BeginScope<TState>(TState state) => NullScope.Instance; public IDisposable BeginScope<TState>(TState state) => NullScope.Instance;
public bool IsEnabled(AspLogLevel logLevel) => true; public bool IsEnabled(AspLogLevel logLevel) => true;
public string Category { get; init; } private string Category { get; init; }
public AspNetToLighthouseLogger(string category) public AspNetToLighthouseLogger(string category)
{ {
@ -21,7 +21,7 @@ public class AspNetToLighthouseLogger : Microsoft.Extensions.Logging.ILogger
{ {
LogLevel level = logLevel.ToLighthouseLevel(); 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; if (exception == null) return;

View file

@ -14,6 +14,15 @@ public class ConsoleLogger : ILogger
// The following is scuffed. // The following is scuffed.
// Beware~ // 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] // Write the level! [Success]
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Console.Write('['); Console.Write('[');
@ -42,7 +51,8 @@ public class ConsoleLogger : ILogger
Console.Write(logLine.Trace.Section); Console.Write(logLine.Trace.Section);
} }
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Console.Write("> "); Console.Write('>');
Console.Write(' ');
Console.ForegroundColor = oldForegroundColor; Console.ForegroundColor = oldForegroundColor;
} }

View file

@ -12,9 +12,9 @@ public class FileLogger : ILogger
public void Log(LogLine line) public void Log(LogLine line)
{ {
FileHelper.EnsureDirectoryCreated(logsDirectory); FileHelper.EnsureDirectoryCreated(logsDirectory);
string time = DateTime.Now.ToString("MM/dd/yyyy-HH:mm:ss.fff");
string contentFile = $"[{ServerStatics.ServerType}] [{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n"; string contentFile = $"[{time}] [{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 contentAll = $"[{time}] [{ServerStatics.ServerType}] [{line.Area}:{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
try try
{ {