Log directory should be implicit, not explicit

This commit is contained in:
Matt Nadareski
2021-01-29 11:06:43 -08:00
parent d59962a812
commit 385b34336f
3 changed files with 17 additions and 8 deletions

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using RombaSharp.Features; using RombaSharp.Features;
using SabreTools.Core; using SabreTools.Core;
using SabreTools.Help; using SabreTools.Help;
using SabreTools.IO;
using SabreTools.Logging; using SabreTools.Logging;
namespace RombaSharp namespace RombaSharp
@@ -38,7 +40,7 @@ namespace RombaSharp
public static void Main(string[] args) public static void Main(string[] args)
{ {
// Perform initial setup and verification // Perform initial setup and verification
LoggerImpl.SetFilename("romba.log", true); LoggerImpl.SetFilename(Path.Combine(PathTool.GetRuntimeDirectory(), "logs", "romba.log"), true);
LoggerImpl.AppendPrefix = true; LoggerImpl.AppendPrefix = true;
LoggerImpl.LowestLogLevel = LogLevel.VERBOSE; LoggerImpl.LowestLogLevel = LogLevel.VERBOSE;
LoggerImpl.ThrowOnError = false; LoggerImpl.ThrowOnError = false;

View File

@@ -16,7 +16,7 @@ namespace SabreTools.Logging
/// <summary> /// <summary>
/// Optional output filename for logs /// Optional output filename for logs
/// </summary> /// </summary>
public static string Filename { get; set; } = null; public static string Filename { get; private set; } = null;
/// <summary> /// <summary>
/// Determines if we're logging to file or not /// Determines if we're logging to file or not
@@ -26,8 +26,7 @@ namespace SabreTools.Logging
/// <summary> /// <summary>
/// Optional output log directory /// Optional output log directory
/// </summary> /// </summary>
/// TODO: Make this either passed in or optional public static string LogDirectory { get; private set; } = null;
public static string LogDirectory { get; set; } = Path.Combine(PathTool.GetRuntimeDirectory(), "logs") + Path.DirectorySeparatorChar;
/// <summary> /// <summary>
/// Determines the lowest log level to output /// Determines the lowest log level to output
@@ -84,11 +83,17 @@ namespace SabreTools.Logging
/// <param name="addDate">True to append a date to the filename, false otherwise</param> /// <param name="addDate">True to append a date to the filename, false otherwise</param>
public static void SetFilename(string filename, bool addDate = true) public static void SetFilename(string filename, bool addDate = true)
{ {
// Set and create the output // Get the full log path
string fullPath = Path.GetFullPath(filename);
// Set the log directory
LogDirectory = Path.GetDirectoryName(fullPath);
// Set the
if (addDate) if (addDate)
Filename = $"{Path.GetFileNameWithoutExtension(filename)} ({DateTime.Now:yyyy-MM-dd HH-mm-ss}).{filename.GetNormalizedExtension()}"; Filename = $"{Path.GetFileNameWithoutExtension(fullPath)} ({DateTime.Now:yyyy-MM-dd HH-mm-ss}).{fullPath.GetNormalizedExtension()}";
else else
Filename = filename; Filename = Path.GetFileName(fullPath);
} }
/// <summary> /// <summary>

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using SabreTools.Features; using SabreTools.Features;
using SabreTools.Core; using SabreTools.Core;
using SabreTools.Help; using SabreTools.Help;
using SabreTools.IO;
using SabreTools.Logging; using SabreTools.Logging;
namespace SabreTools namespace SabreTools
@@ -31,7 +33,7 @@ namespace SabreTools
public static void Main(string[] args) public static void Main(string[] args)
{ {
// Perform initial setup and verification // Perform initial setup and verification
LoggerImpl.SetFilename("sabretools.log", true); LoggerImpl.SetFilename(Path.Combine(PathTool.GetRuntimeDirectory(), "logs", "sabretools.log"), true);
LoggerImpl.AppendPrefix = true; LoggerImpl.AppendPrefix = true;
LoggerImpl.LowestLogLevel = LogLevel.VERBOSE; LoggerImpl.LowestLogLevel = LogLevel.VERBOSE;
LoggerImpl.ThrowOnError = false; LoggerImpl.ThrowOnError = false;