Merge pull request #486 from CoderCow/patch-1
Configurable Path for the Logs
This commit is contained in:
commit
75d3be63e7
4 changed files with 88 additions and 37 deletions
|
|
@ -407,7 +407,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args.Player.SendErrorMessage(String.Format("Syntax: /login{0} <password>", TShock.Config.AllowLoginAnyUsername ? " " : " [username]"));
|
args.Player.SendErrorMessage(String.Format("Syntax: /login{0} <password>", TShock.Config.AllowLoginAnyUsername ? " [username]" : " "));
|
||||||
args.Player.SendErrorMessage("If you forgot your password, there is no way to recover it.");
|
args.Player.SendErrorMessage("If you forgot your password, there is no way to recover it.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -742,6 +742,7 @@ namespace TShockAPI
|
||||||
public static void WorldInfo(CommandArgs args)
|
public static void WorldInfo(CommandArgs args)
|
||||||
{
|
{
|
||||||
args.Player.SendInfoMessage("World name: " + Main.worldName);
|
args.Player.SendInfoMessage("World name: " + Main.worldName);
|
||||||
|
args.Player.SendInfoMessage("World size: {0}x{1}", Main.maxTilesX, Main.maxTilesY);
|
||||||
args.Player.SendInfoMessage("World ID: " + Main.worldID);
|
args.Player.SendInfoMessage("World ID: " + Main.worldID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,8 @@ namespace TShockAPI
|
||||||
|
|
||||||
[Description("Allows stacks in chests to be beyond the stack limit")] public bool IgnoreChestStacksOnLoad = false;
|
[Description("Allows stacks in chests to be beyond the stack limit")] public bool IgnoreChestStacksOnLoad = false;
|
||||||
|
|
||||||
|
[Description("The path of the directory where logs should be written into.")] public string LogPath = "tshock";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a configuration file from a given path
|
/// Reads a configuration file from a given path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,21 @@
|
||||||
using System;
|
/*
|
||||||
|
TShock, a server mod for Terraria
|
||||||
|
Copyright (C) 2011-2012 The TShock Team
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -190,12 +207,14 @@ namespace TShockAPI {
|
||||||
string termString;
|
string termString;
|
||||||
if (termFormatter != null)
|
if (termFormatter != null)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
termString = termFormatter(term);
|
termString = termFormatter(term);
|
||||||
|
|
||||||
if (termString == null)
|
if (termString == null)
|
||||||
continue;
|
continue;
|
||||||
} catch (Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new ArgumentException(
|
throw new ArgumentException(
|
||||||
"The method represented by termFormatter has thrown an exception. See inner exception for details.", ex);
|
"The method represented by termFormatter has thrown an exception. See inner exception for details.", ex);
|
||||||
|
|
@ -209,9 +228,8 @@ namespace TShockAPI {
|
||||||
bool goesOnNextLine = (lineBuilder.Length + termString.Length > maxCharsPerLine);
|
bool goesOnNextLine = (lineBuilder.Length + termString.Length > maxCharsPerLine);
|
||||||
if (!goesOnNextLine)
|
if (!goesOnNextLine)
|
||||||
{
|
{
|
||||||
if (lineBuilder.Length > 0) {
|
if (lineBuilder.Length > 0)
|
||||||
lineBuilder.Append(separator);
|
lineBuilder.Append(separator);
|
||||||
}
|
|
||||||
lineBuilder.Append(termString);
|
lineBuilder.Append(termString);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,15 @@ namespace TShockAPI
|
||||||
[APIVersion(1, 13)]
|
[APIVersion(1, 13)]
|
||||||
public class TShock : TerrariaPlugin
|
public class TShock : TerrariaPlugin
|
||||||
{
|
{
|
||||||
private const string LogFormatDefault = "yyyy-MM-dd_HH-mm-ss";
|
|
||||||
private static string LogFormat = LogFormatDefault;
|
|
||||||
private static bool LogClear = false;
|
|
||||||
public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version;
|
public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
public static readonly string VersionCodename = "Welcome to the future.";
|
public static readonly string VersionCodename = "Welcome to the future.";
|
||||||
|
|
||||||
public static string SavePath = "tshock";
|
public static string SavePath = "tshock";
|
||||||
|
private const string LogFormatDefault = "yyyy-MM-dd_HH-mm-ss";
|
||||||
|
private static string LogFormat = LogFormatDefault;
|
||||||
|
private const string LogPathDefault = "tshock";
|
||||||
|
private static string LogPath = LogPathDefault;
|
||||||
|
private static bool LogClear = false;
|
||||||
|
|
||||||
public static TSPlayer[] Players = new TSPlayer[Main.maxPlayers];
|
public static TSPlayer[] Players = new TSPlayer[Main.maxPlayers];
|
||||||
public static BanManager Bans;
|
public static BanManager Bans;
|
||||||
|
|
@ -112,35 +114,57 @@ namespace TShockAPI
|
||||||
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
|
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
HandleCommandLine(Environment.GetCommandLineArgs());
|
|
||||||
|
|
||||||
if (!Directory.Exists(SavePath))
|
|
||||||
Directory.CreateDirectory(SavePath);
|
|
||||||
|
|
||||||
DateTime now = DateTime.Now;
|
|
||||||
string logFilename;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logFilename = Path.Combine(SavePath, now.ToString(LogFormat)+".log");
|
HandleCommandLine(Environment.GetCommandLineArgs());
|
||||||
}
|
|
||||||
catch(Exception)
|
if (Version.Major >= 4)
|
||||||
{
|
getTShockAscii();
|
||||||
// Problem with the log format use the default
|
|
||||||
logFilename = Path.Combine(SavePath, now.ToString(LogFormatDefault) + ".log");
|
if (!Directory.Exists(SavePath))
|
||||||
}
|
Directory.CreateDirectory(SavePath);
|
||||||
|
|
||||||
|
ConfigFile.ConfigRead += OnConfigRead;
|
||||||
|
FileTools.SetupConfig();
|
||||||
|
|
||||||
|
DateTime now = DateTime.Now;
|
||||||
|
string logFilename;
|
||||||
|
string logPathSetupWarning = null;
|
||||||
|
// Log path was not already set by the command line parameter?
|
||||||
|
if (LogPath == LogPathDefault)
|
||||||
|
LogPath = Config.LogPath;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logFilename = Path.Combine(LogPath, now.ToString(LogFormat)+".log");
|
||||||
|
if (!Directory.Exists(LogPath))
|
||||||
|
Directory.CreateDirectory(LogPath);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
logPathSetupWarning = "Could not apply the given log path / log format, defaults will be used. Exception details:\n" + ex;
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine(logPathSetupWarning);
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
// Problem with the log path or format use the default
|
||||||
|
logFilename = Path.Combine(LogPathDefault, now.ToString(LogFormatDefault) + ".log");
|
||||||
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Log.Initialize(logFilename, LogLevel.All, false);
|
Log.Initialize(logFilename, LogLevel.All, false);
|
||||||
#else
|
#else
|
||||||
Log.Initialize(logFilename, LogLevel.All & ~LogLevel.Debug, LogClear);
|
Log.Initialize(logFilename, LogLevel.All & ~LogLevel.Debug, LogClear);
|
||||||
#endif
|
#endif
|
||||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
if (logPathSetupWarning != null)
|
||||||
|
Log.Warn(logPathSetupWarning);
|
||||||
if (Version.Major >= 4)
|
|
||||||
{
|
|
||||||
getTShockAscii();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
// Will be handled by the server api and written to its crashlog.txt.
|
||||||
|
throw new Exception("Fatal TShock initialization exception. See inner exception for details.", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Further exceptions are written to TShock's log from now on.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
|
if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
|
||||||
|
|
@ -151,9 +175,6 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
File.WriteAllText(Path.Combine(SavePath, "tshock.pid"), Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture));
|
File.WriteAllText(Path.Combine(SavePath, "tshock.pid"), Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture));
|
||||||
|
|
||||||
ConfigFile.ConfigRead += OnConfigRead;
|
|
||||||
FileTools.SetupConfig();
|
|
||||||
|
|
||||||
HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs());
|
HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs());
|
||||||
|
|
||||||
if (Config.StorageType.ToLower() == "sqlite")
|
if (Config.StorageType.ToLower() == "sqlite")
|
||||||
|
|
@ -446,9 +467,13 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "-dump":
|
case "-logpath":
|
||||||
ConfigFile.DumpDescriptions();
|
path = parms[++i];
|
||||||
Permissions.DumpDescriptions();
|
if (path.IndexOfAny(Path.GetInvalidPathChars()) == -1)
|
||||||
|
{
|
||||||
|
LogPath = path;
|
||||||
|
Log.ConsoleInfo("Log path has been set to " + path);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "-logformat":
|
case "-logformat":
|
||||||
|
|
@ -458,6 +483,11 @@ namespace TShockAPI
|
||||||
case "-logclear":
|
case "-logclear":
|
||||||
bool.TryParse(parms[++i], out LogClear);
|
bool.TryParse(parms[++i], out LogClear);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "-dump":
|
||||||
|
ConfigFile.DumpDescriptions();
|
||||||
|
Permissions.DumpDescriptions();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue