From d7696912e007a2b455a2fd5e1974924d2efe83b3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 24 Feb 2018 16:51:37 -0500 Subject: reimplement log parser with serverside parsing and vue.js frontend --- .../Framework/LogParsing/Models/LogLevel.cs | 24 +++++++++++ .../Framework/LogParsing/Models/LogMessage.cs | 24 +++++++++++ .../Framework/LogParsing/Models/ModInfo.cs | 24 +++++++++++ .../Framework/LogParsing/Models/ParsedLog.cs | 47 ++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 src/SMAPI.Web/Framework/LogParsing/Models/LogLevel.cs create mode 100644 src/SMAPI.Web/Framework/LogParsing/Models/LogMessage.cs create mode 100644 src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs create mode 100644 src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs (limited to 'src/SMAPI.Web/Framework/LogParsing/Models') diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/LogLevel.cs b/src/SMAPI.Web/Framework/LogParsing/Models/LogLevel.cs new file mode 100644 index 00000000..40d21bf8 --- /dev/null +++ b/src/SMAPI.Web/Framework/LogParsing/Models/LogLevel.cs @@ -0,0 +1,24 @@ +namespace StardewModdingAPI.Web.Framework.LogParsing.Models +{ + /// The log severity levels. + public enum LogLevel + { + /// Tracing info intended for developers. + Trace, + + /// Troubleshooting info that may be relevant to the player. + Debug, + + /// Info relevant to the player. This should be used judiciously. + Info, + + /// An issue the player should be aware of. This should be used rarely. + Warn, + + /// A message indicating something went wrong. + Error, + + /// Important information to highlight for the player when player action is needed (e.g. new version available). This should be used rarely to avoid alert fatigue. + Alert + } +} diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/LogMessage.cs b/src/SMAPI.Web/Framework/LogParsing/Models/LogMessage.cs new file mode 100644 index 00000000..baeac83c --- /dev/null +++ b/src/SMAPI.Web/Framework/LogParsing/Models/LogMessage.cs @@ -0,0 +1,24 @@ +namespace StardewModdingAPI.Web.Framework.LogParsing.Models +{ + /// A parsed log message. + public class LogMessage + { + /********* + ** Accessors + *********/ + /// The local time when the log was posted. + public string Time { get; set; } + + /// The log level. + public LogLevel Level { get; set; } + + /// The mod name. + public string Mod { get; set; } + + /// The log text. + public string Text { get; set; } + + /// The number of times this message was repeated consecutively. + public int Repeated { get; set; } + } +} diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs new file mode 100644 index 00000000..2005e61f --- /dev/null +++ b/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs @@ -0,0 +1,24 @@ +namespace StardewModdingAPI.Web.Framework.LogParsing.Models +{ + /// Metadata about a mod or content pack in the log. + public class LogModInfo + { + /********* + ** Accessors + *********/ + /// The mod name. + public string Name { get; set; } + + /// The mod author. + public string Author { get; set; } + + /// The mod version. + public string Version { get; set; } + + /// The mod description. + public string Description { get; set; } + + /// The number of errors logged by this mod. + public int Errors { get; set; } + } +} diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs b/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs new file mode 100644 index 00000000..31ef2fe1 --- /dev/null +++ b/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs @@ -0,0 +1,47 @@ +using System; + +namespace StardewModdingAPI.Web.Framework.LogParsing.Models +{ + /// Parsed metadata for a log. + public class ParsedLog + { + /********* + ** Accessors + *********/ + /**** + ** Metadata + ****/ + /// Whether the log file was successfully parsed. + public bool IsValid { get; set; } + + /// An error message indicating why the log file is invalid. + public string Error { get; set; } + + /// The raw text if is false. + public string RawTextIfError { get; set; } + + /**** + ** Log data + ****/ + /// The SMAPI version. + public string ApiVersion { get; set; } + + /// The game version. + public string GameVersion { get; set; } + + /// The player's operating system. + public string OperatingSystem { get; set; } + + /// The mod folder path. + public string ModPath { get; set; } + + /// The ISO 8601 timestamp when the log was started. + public DateTimeOffset Timestamp { get; set; } + + /// Metadata about installed mods and content packs. + public LogModInfo[] Mods { get; set; } = new LogModInfo[0]; + + /// The log messages. + public LogMessage[] Messages { get; set; } + } +} -- cgit From 691310d16e6873b83c55f62a59d5010dd8bb7e98 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 24 Feb 2018 16:52:38 -0500 Subject: add content pack support to log parser --- docs/release-notes.md | 1 + src/SMAPI.Web/Framework/LogParsing/LogParser.cs | 23 ++++++++++++++++++++++ .../Framework/LogParsing/Models/ModInfo.cs | 3 +++ src/SMAPI.Web/Views/LogParser/Index.cshtml | 19 +++++++++++++++++- src/SMAPI.Web/wwwroot/Content/css/log-parser.css | 6 ++++++ 5 files changed, 51 insertions(+), 1 deletion(-) (limited to 'src/SMAPI.Web/Framework/LogParsing/Models') diff --git a/docs/release-notes.md b/docs/release-notes.md index 03b6dd77..da651be2 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -22,6 +22,7 @@ * For the [log parser][]: * Significantly reduced download size when viewing files with repeated errors. + * Added support for SMAPI 2.5 content packs. * Improved parse error handling. * Fixed 'log started' field showing incorrect date. diff --git a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs index 1c3b5671..23a1baa4 100644 --- a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs +++ b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs @@ -31,6 +31,12 @@ namespace StardewModdingAPI.Web.Framework.LogParsing /// A regex pattern matching an entry in SMAPI's mod list. private readonly Regex ModListEntryPattern = new Regex(@"^ (?.+) (?.+) by (?.+) \| (?.+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + /// A regex pattern matching the start of SMAPI's content pack list. + private readonly Regex ContentPackListStartPattern = new Regex(@"^Loaded \d+ content packs:$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + /// A regex pattern matching an entry in SMAPI's content pack list. + private readonly Regex ContentPackListEntryPattern = new Regex(@"^ (?.+) (?.+) by (?.+) \| for (?.+?) \| (?.+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + /********* ** Public methods @@ -62,6 +68,7 @@ namespace StardewModdingAPI.Web.Framework.LogParsing LogModInfo smapiMod = new LogModInfo { Name = "SMAPI", Author = "Pathoschild", Description = "" }; IDictionary mods = new Dictionary(); bool inModList = false; + bool inContentPackList = false; foreach (LogMessage message in log.Messages) { // collect stats @@ -79,6 +86,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing // update flags if (inModList && !this.ModListEntryPattern.IsMatch(message.Text)) inModList = false; + if (inContentPackList && !this.ContentPackListEntryPattern.IsMatch(message.Text)) + inContentPackList = false; // mod list if (!inModList && message.Level == LogLevel.Info && this.ModListStartPattern.IsMatch(message.Text)) @@ -93,6 +102,20 @@ namespace StardewModdingAPI.Web.Framework.LogParsing mods[name] = new LogModInfo { Name = name, Author = author, Version = version, Description = description }; } + // content pack list + else if (!inContentPackList && message.Level == LogLevel.Info && this.ContentPackListStartPattern.IsMatch(message.Text)) + inContentPackList = true; + else if (inContentPackList) + { + Match match = this.ContentPackListEntryPattern.Match(message.Text); + string name = match.Groups["name"].Value; + string version = match.Groups["version"].Value; + string author = match.Groups["author"].Value; + string description = match.Groups["description"].Value; + string forMod = match.Groups["for"].Value; + mods[name] = new LogModInfo { Name = name, Author = author, Version = version, Description = description, ContentPackFor = forMod }; + } + // platform info line else if (message.Level == LogLevel.Info && this.InfoLinePattern.IsMatch(message.Text)) { diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs index 2005e61f..8c84ab38 100644 --- a/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs +++ b/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs @@ -18,6 +18,9 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models /// The mod description. public string Description { get; set; } + /// The name of the mod for which this is a content pack (if applicable). + public string ContentPackFor { get; set; } + /// The number of errors logged by this mod. public int Errors { get; set; } } diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml index 8d1abbb1..20e20ee1 100644 --- a/src/SMAPI.Web/Views/LogParser/Index.cshtml +++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml @@ -1,5 +1,10 @@ @{ ViewData["Title"] = "SMAPI log parser"; + + Dictionary contentPacks = Model.ParsedLog?.Mods + ?.GroupBy(mod => mod.ContentPackFor) + .Where(group => group.Key != null) + .ToDictionary(group => group.Key, group => group.ToArray()); } @using Newtonsoft.Json @using StardewModdingAPI.Web.Framework.LogParsing.Models @@ -69,10 +74,22 @@ show all hide all - @foreach (var mod in Model.ParsedLog.Mods) + @foreach (var mod in Model.ParsedLog.Mods.Where(p => p.ContentPackFor == null)) { + + @mod.Name + @if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList)) + { +
+ @foreach (var contentPack in contentPackList) + { + +@contentPack.Name @contentPack.Version + } +
+ } + @mod.Version @mod.Author @if (mod.Errors == 0) diff --git a/src/SMAPI.Web/wwwroot/Content/css/log-parser.css b/src/SMAPI.Web/wwwroot/Content/css/log-parser.css index a3be0c85..cbf09ffe 100644 --- a/src/SMAPI.Web/wwwroot/Content/css/log-parser.css +++ b/src/SMAPI.Web/wwwroot/Content/css/log-parser.css @@ -97,6 +97,12 @@ table#mods { opacity: 0.5; } +#mods .content-packs { + margin-left: 1em; + font-size: 0.9em; + font-style: italic; +} + #metadata td:first-child { padding-right: 5px; } -- cgit