Add log level input

This commit is contained in:
Matt Nadareski
2021-02-03 10:09:40 -08:00
parent 6f2252f804
commit 6139f7672d
15 changed files with 114 additions and 16 deletions

View File

@@ -785,4 +785,19 @@ namespace SabreTools.Core
}
#endregion
#region Logging
/// <summary>
/// Severity of the logging statement
/// </summary>
public enum LogLevel
{
VERBOSE = 0,
USER,
WARNING,
ERROR,
}
#endregion
}

View File

@@ -205,6 +205,10 @@ Options:
date. It will also treat all archives as possible games and add all three
hashes (CRC, MD5, SHA-1) for each file.
-ll=, --log-level= Set the lowest log level for output
Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error
-nm, --skip-md5 Don't include MD5 in output
This allows the user to skip calculating the MD5 for each of the
files which will speed up the creation of the DAT.
@@ -437,6 +441,10 @@ Options:
- Nintendo Super Famicom / Super Nintendo Entertainment System
- Nintendo Super Famicom / Super Nintendo Entertainment System SPC
-ll=, --log-level= Set the lowest log level for output
Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error
-out=, --output-dir= Set output directory
This sets an output folder to be used when the files are created. If
a path is not defined, the runtime directory is used instead.
@@ -463,6 +471,10 @@ Options:
- Nintendo Super Famicom / Super Nintendo Entertainment System
- Nintendo Super Famicom / Super Nintendo Entertainment System SPC
-ll=, --log-level= Set the lowest log level for output
Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error
-out=, --output-dir= Set output directory
This sets an output folder to be used when the files are created. If
a path is not defined, the runtime directory is used instead.
@@ -472,6 +484,10 @@ Options:
file(s). By default all files will be rebuilt to uncompressed folders in
the output directory.
-ll=, --log-level= Set the lowest log level for output
Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error
-dat=, --dat= Input DAT to be used
User-supplied DAT for use in all operations. Multiple instances of
this flag are allowed.
@@ -610,6 +626,10 @@ Options:
possible criteria. See the individual input information for details. More
than one split type is allowed at a time.
-ll=, --log-level= Set the lowest log level for output
Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error
-ot=, --output-type= Output DATs to a specified format
Add outputting the created DAT to known format. Multiple instances of
this flag are allowed.
@@ -727,6 +747,10 @@ Options:
- Items that include a SHA-512
- Items with Nodump status
-ll=, --log-level= Set the lowest log level for output
Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error
-srt=, --report-type= Output statistics to a specified format
Add outputting the created DAT to known format. Multiple instances of
this flag are allowed.
@@ -764,6 +788,10 @@ Options:
different programs that performed DAT manipulation that work better
together.
-ll=, --log-level= Set the lowest log level for output
Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error
-ot=, --output-type= Output DATs to a specified format
Add outputting the created DAT to known format. Multiple instances of
this flag are allowed.
@@ -1158,6 +1186,10 @@ Options:
within. This will only do a direct verification of the items within and
will create a fixdat afterwards for missing files.
-ll=, --log-level= Set the lowest log level for output
Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error
-dat=, --dat= Input DAT to be used
User-supplied DAT for use in all operations. Multiple instances of
this flag are allowed.

View File

@@ -949,6 +949,23 @@ namespace SabreTools.Core.Tools
};
}
/// <summary>
/// Get LogLevel value from input string
/// </summary>
/// <param name="logLevel">String to get value from</param>
/// <returns>LogLevel value corresponding to the string</returns>
public static LogLevel AsLogLevel(this string logLevel)
{
return logLevel.ToLowerInvariant() switch
{
"verbose" => LogLevel.VERBOSE,
"user" => LogLevel.USER,
"warning" => LogLevel.WARNING,
"error" => LogLevel.ERROR,
_ => LogLevel.VERBOSE,
};
}
/// <summary>
/// Get MachineField value from input string
/// </summary>

View File

@@ -1,13 +0,0 @@
namespace SabreTools.Logging
{
/// <summary>
/// Severity of the logging statement
/// </summary>
public enum LogLevel
{
VERBOSE = 0,
USER,
WARNING,
ERROR,
}
}

View File

@@ -1,5 +1,7 @@
using System;
using SabreTools.Core;
namespace SabreTools.Logging
{
/// <summary>

View File

@@ -2,6 +2,7 @@
using System.IO;
using System.Text;
using SabreTools.Core;
using SabreTools.IO;
namespace SabreTools.Logging

View File

@@ -1555,6 +1555,21 @@ Possible values are: None, Zip, Unzip, Partial, Flat");
}
}
internal const string LogLevelStringValue = "log-level";
internal static Feature LogLevelStringInput
{
get
{
return new Feature(
LogLevelStringValue,
new List<string>() { "-ll", "--log-level" },
"Set the lowest log level for output",
ParameterType.String,
longDescription: @"Set the lowest log level for output.
Possible values are: Verbose, User, Warning, Error");
}
}
internal const string NameStringValue = "name";
internal static Feature NameStringInput
{
@@ -1735,6 +1750,11 @@ Some special strings that can be used:
/// </summary>
protected DatHeader Header { get; set; }
/// <summary>
/// Lowest log level for output
/// </summary>
public LogLevel LogLevel { get; protected set; }
/// <summary>
/// Output directory
/// </summary>
@@ -1816,6 +1836,7 @@ Some special strings that can be used:
Extras = GetExtras(features);
Filter = GetFilter(features);
Header = GetDatHeader(features);
LogLevel = GetString(features, LogLevelStringValue).AsLogLevel();
OutputDir = GetString(features, OutputDirStringValue).Trim('"');
Remover = GetRemover(features);
Splitter = GetSplitter(features);

View File

@@ -44,6 +44,9 @@ Set the output directory: output(outdir);
Write the internal items: write([overwrite = true]);
Reset the internal state: reset();";
Features = new Dictionary<string, Help.Feature>();
// Common Features
AddFeature(LogLevelStringInput);
}
public override void ProcessFeatures(Dictionary<string, Help.Feature> features)

View File

@@ -22,6 +22,9 @@ namespace SabreTools.Features
LongDescription = "Create a DAT file from an input directory or set of files. By default, this will output a DAT named based on the input directory and the current date. It will also treat all archives as possible games and add all three hashes (CRC, MD5, SHA-1) for each file.";
Features = new Dictionary<string, Help.Feature>();
// Common Features
AddFeature(LogLevelStringInput);
// Hash Features
AddFeature(SkipMd5Flag);
AddFeature(SkipSha1Flag);

View File

@@ -34,6 +34,9 @@ The following systems have headers that this program can work with:
- Nintendo Super Famicom / Super Nintendo Entertainment System SPC";
Features = new Dictionary<string, Feature>();
// Common Features
AddFeature(LogLevelStringInput);
AddFeature(OutputDirStringInput);
AddFeature(NoStoreHeaderFlag);
}

View File

@@ -4,6 +4,8 @@ using SabreTools.Help;
namespace SabreTools.Features
{
// TODO: With the introduction of the `--log-level` input, can we create a better way
// to handle "universal" flags? Having script as its own feature is not ideal.
internal class Script : BaseFeature
{
public const string Value = "Script";

View File

@@ -23,6 +23,9 @@ namespace SabreTools.Features
LongDescription = "This feature allows the user to quickly rebuild based on a supplied DAT file(s). By default all files will be rebuilt to uncompressed folders in the output directory.";
Features = new Dictionary<string, Feature>();
// Common Features
AddFeature(LogLevelStringInput);
AddFeature(DatListInput);
AddFeature(OutputDirStringInput);
AddFeature(DepotFlag);

View File

@@ -23,6 +23,9 @@ namespace SabreTools.Features
LongDescription = "This feature allows the user to split input DATs by a number of different possible criteria. See the individual input information for details. More than one split type is allowed at a time.";
Features = new Dictionary<string, Help.Feature>();
// Common Features
AddFeature(LogLevelStringInput);
AddFeature(OutputTypeListInput);
this[OutputTypeListInput].AddFeature(DeprecatedFlag);
AddFeature(OutputDirStringInput);

View File

@@ -23,6 +23,9 @@ namespace SabreTools.Features
LongDescription = "When used, this will use an input DAT or set of DATs to blindly check against an input folder. The base of the folder is considered the base for the combined DATs and games are either the directories or archives within. This will only do a direct verification of the items within and will create a fixdat afterwards for missing files.";
Features = new Dictionary<string, Feature>();
// Common Features
AddFeature(LogLevelStringInput);
AddFeature(DatListInput);
AddFeature(DepotFlag);
this[DepotFlag].AddFeature(DepotDepthInt32Input);

View File

@@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.IO;
using SabreTools.Features;
using SabreTools.Core;
using SabreTools.Features;
using SabreTools.Help;
using SabreTools.IO;
using SabreTools.Logging;
@@ -109,6 +109,9 @@ namespace SabreTools
return;
}
// Set the new log level based on settings
LoggerImpl.LowestLogLevel = feature.LogLevel;
// Now process the current feature
Dictionary<string, Feature> features = _help.GetEnabledFeatures();
switch (featureName)