Skip to content

Commit

Permalink
Log viewer changes (#70)
Browse files Browse the repository at this point in the history
* Log viewer will now only scan a maximum of 10k log lines (perf).

* Fix for bug when log level contains spaces.

* Removed invalid log download context menu item
  • Loading branch information
CraigHawker committed Sep 12, 2022
1 parent 77dd461 commit 3955a40
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public virtual IEnumerable<CustomDomainCommand> GetDefaultLogTargetDownloadComma
// If they can only download them all then make sure the item on the domain menu
// reflects that.
var command = Dashboards.Commands.DownloadSelectedLogsDashboardCommand.Create();
command.Locations = new List<ICommandLocation> { new DomainMenuCommandLocation() };
command.Locations = new List<ICommandLocation> { };
yield return command;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public class RetrieveLatestLogEntriesCommand
/// </summary>
public static string CommandId = "__RetrieveLatestLogEntries";

/// <summary>
/// The maximum number of lines to scan to try to retrieve data.
/// Setting this to a larger number may mean that it takes longer to retrieve data,
/// possibly timing out.
/// </summary>
public int MaximumLinesToScan { get; set; } = 10000;

private RetrieveLatestLogEntriesCommand() { }

public static RetrieveLatestLogEntriesCommand Create()
Expand Down Expand Up @@ -190,12 +197,18 @@ ClientOperations clientOps
&& defaultLoggingConfiguration?.Advanced?.Layout != "${longdate}\t(v${application-version})\t${logger}\t${log-context}\t${level}:\t${message}${onexception:${newline}${exception:format=ToString:innerformat=ToString:separator=\r\n}}")
logEntries.StructuredEntries = false;
}
var linesRead = 0;

foreach(var logFile in logFiles)
{
// Only read a certain number of entries.
if (logEntries.Entries.Count >= requestParameters.MaximumNumberOfLogEntries)
if (
logEntries.Entries.Count >= requestParameters.MaximumNumberOfLogEntries
|| linesRead > this.MaximumLinesToScan)
{
logEntries.ReachedMaximumLinesToScan = linesRead > this.MaximumLinesToScan;
break;
}

// Sanity and safety check.
// All paths must be inside the log folder.
Expand All @@ -211,8 +224,12 @@ ClientOperations clientOps
var logEntry = new LogEntry();
foreach (var line in reader)
{
linesRead++;
if (linesRead > this.MaximumLinesToScan)
break;

// Add the line to the log entry.
logEntry.FullLine = line + Environment.NewLine + logEntry.FullLine;
logEntry.PopulateFromFullLine(line + Environment.NewLine + logEntry.FullLine);

// If we are dealing with structured entries then we can analyse them further.
if (logEntries.StructuredEntries)
Expand Down Expand Up @@ -629,29 +646,27 @@ public string FullLine
this.Add(fullLineKey, null);
return this[fullLineKey];
}
set
{
this[fullLineKey] = value;
this.PopulateFromFullLine();
}
}

protected virtual void PopulateFromFullLine()
public virtual bool PopulateFromFullLine(string fullLine)
{
this[fullLineKey] = fullLine;

foreach (var key in this.Keys)
if (key != fullLineKey)
this.Remove(key);
if (string.IsNullOrWhiteSpace(this.FullLine))
return;
return false;
var match = ParseLineRegularExpression.Match(this.FullLine);
if (!match.Success)
return;
return false;

// Add each in turn.
foreach (var name in ParseLineRegularExpression.GetGroupNames())
{
this.Add(name, match.Groups[name].Value);
}
return true;
}

public override string ToString()
Expand All @@ -671,6 +686,9 @@ internal class LogEntries

[DataMember(Name = "structuredEntries")]
public bool StructuredEntries { get; set; }

[DataMember(Name = "reachedMaximumLinesToScan")]
public bool ReachedMaximumLinesToScan { get; set; }
}
}
}
26 changes: 22 additions & 4 deletions MFiles.VAF.Extensions/Resources/DisplayLatestLogEntries.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
body.unstructured #scrollPanel thead {
display: none;
}
#unstructured {
#unstructured, #reachedMaximum {
display: none;
padding: 5px 15px;
padding-left: 30px;
Expand All @@ -131,10 +131,10 @@
background-color: lightGoldenrodYellow;
margin-bottom: 10px;
}
body.unstructured #unstructured{
body.unstructured #unstructured,
body.reachedMaximum #reachedMaximum {
display: block;
}

.loading, .no-entries {
text-align: center;
}
Expand Down Expand Up @@ -228,6 +228,13 @@
{
document.body.classList.remove("unstructured");
}
if (logEntries.reachedMaximumLinesToScan)
{
document.body.classList.add("reachedMaximum");
} else
{
document.body.classList.remove("reachedMaximum");
}

// Remove any existing log entries.
var table = document.getElementById("logEntries");
Expand Down Expand Up @@ -263,7 +270,15 @@
tr.appendChild(createTableCellWithContent(entry["LogContext"]));
tr.appendChild(createTableCellWithContent(entry["LogLevel"]));
tr.appendChild(createTableCellWithContent(entry["Message"], ["message"]));
tr.classList.add(entry["LogLevel"].toLowerCase());
try
{
if ((entry["LogLevel"] + "").length != 0)
tr.classList.add(entry["LogLevel"].toLowerCase());
} catch (e)
{
console.log("Could not add css class of '" + entry["LogLevel"] + "' to row.")
}

}
else
{
Expand Down Expand Up @@ -481,6 +496,9 @@
<div id="unstructured">
The logger is not using the default log layout, so structured formatting cannot be applied.
</div>
<div id="reachedMaximum">
The maximum number of lines to scan was reached; download the logs for more detailed analysis.
</div>
<table id="logEntries">
<thead>
<tr>
Expand Down

0 comments on commit 3955a40

Please sign in to comment.