Add timestamps to server log files
Servers are now writing timestamps to the log files using the the ISO 8601 timestamp format defined in the game server settings.
This commit is contained in:
@@ -295,7 +295,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
Log.AddChannel("perf", "perf.log");
|
Log.AddChannel("perf", "perf.log");
|
||||||
Log.AddChannel("debug", "debug.log");
|
Log.AddChannel("debug", "debug.log");
|
||||||
Log.AddChannel("server", "server.log");
|
Log.AddChannel("server", "server.log", true);
|
||||||
Log.AddChannel("sound", "sound.log");
|
Log.AddChannel("sound", "sound.log");
|
||||||
Log.AddChannel("graphics", "graphics.log");
|
Log.AddChannel("graphics", "graphics.log");
|
||||||
Log.AddChannel("geoip", "geoip.log");
|
Log.AddChannel("geoip", "geoip.log");
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ namespace OpenRA.Server
|
|||||||
|
|
||||||
public Server(IPEndPoint endpoint, ServerSettings settings, ModData modData, bool dedicated)
|
public Server(IPEndPoint endpoint, ServerSettings settings, ModData modData, bool dedicated)
|
||||||
{
|
{
|
||||||
Log.AddChannel("server", "server.log");
|
Log.AddChannel("server", "server.log", true);
|
||||||
|
|
||||||
listener = new TcpListener(endpoint);
|
listener = new TcpListener(endpoint);
|
||||||
listener.Start();
|
listener.Start();
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ namespace OpenRA
|
|||||||
[Desc("Enable client-side report generation to help debug desync errors.")]
|
[Desc("Enable client-side report generation to help debug desync errors.")]
|
||||||
public bool EnableSyncReports = false;
|
public bool EnableSyncReports = false;
|
||||||
|
|
||||||
public string TimestampFormat = "s";
|
[Desc("Sets the timestamp format. Defaults to the ISO 8601 standard.")]
|
||||||
|
public string TimestampFormat = "yyyy-MM-ddTHH:mm:ss";
|
||||||
|
|
||||||
public ServerSettings Clone()
|
public ServerSettings Clone()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace OpenRA
|
|||||||
public struct ChannelInfo
|
public struct ChannelInfo
|
||||||
{
|
{
|
||||||
public string Filename;
|
public string Filename;
|
||||||
|
public bool IsTimestamped;
|
||||||
public TextWriter Writer;
|
public TextWriter Writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ namespace OpenRA
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddChannel(string channelName, string baseFilename)
|
public static void AddChannel(string channelName, string baseFilename, bool isTimestamped = false)
|
||||||
{
|
{
|
||||||
lock (Channels)
|
lock (Channels)
|
||||||
{
|
{
|
||||||
@@ -66,6 +67,7 @@ namespace OpenRA
|
|||||||
new ChannelInfo
|
new ChannelInfo
|
||||||
{
|
{
|
||||||
Filename = filename,
|
Filename = filename,
|
||||||
|
IsTimestamped = isTimestamped,
|
||||||
Writer = TextWriter.Synchronized(writer)
|
Writer = TextWriter.Synchronized(writer)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -75,22 +77,35 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Write(string channel, string value)
|
public static void Write(string channelName, string value)
|
||||||
{
|
{
|
||||||
var writer = Channel(channel).Writer;
|
var channel = Channel(channelName);
|
||||||
|
var writer = channel.Writer;
|
||||||
if (writer == null)
|
if (writer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
writer.WriteLine(value);
|
if (!channel.IsTimestamped)
|
||||||
|
writer.WriteLine(value);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var timestamp = DateTime.Now.ToString(Game.Settings.Server.TimestampFormat);
|
||||||
|
writer.WriteLine("[{0}] {1}", timestamp, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Write(string channel, string format, params object[] args)
|
public static void Write(string channelName, string format, params object[] args)
|
||||||
{
|
{
|
||||||
var writer = Channel(channel).Writer;
|
var channel = Channel(channelName);
|
||||||
if (writer == null)
|
if (channel.Writer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
writer.WriteLine(format, args);
|
if (!channel.IsTimestamped)
|
||||||
|
channel.Writer.WriteLine(format, args);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var timestamp = DateTime.Now.ToString(Game.Settings.Server.TimestampFormat);
|
||||||
|
channel.Writer.WriteLine("[{0}] {1}", timestamp, format.F(args));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ namespace OpenRA.Server
|
|||||||
if (supportDirArg != null)
|
if (supportDirArg != null)
|
||||||
Platform.OverrideSupportDir(supportDirArg);
|
Platform.OverrideSupportDir(supportDirArg);
|
||||||
|
|
||||||
Log.AddChannel("debug", "dedicated-debug.log");
|
Log.AddChannel("debug", "dedicated-debug.log", true);
|
||||||
Log.AddChannel("perf", "dedicated-perf.log");
|
Log.AddChannel("perf", "dedicated-perf.log", true);
|
||||||
Log.AddChannel("server", "dedicated-server.log");
|
Log.AddChannel("server", "dedicated-server.log", true);
|
||||||
Log.AddChannel("nat", "dedicated-nat.log");
|
Log.AddChannel("nat", "dedicated-nat.log", true);
|
||||||
|
|
||||||
// Special case handling of Game.Mod argument: if it matches a real filesystem path
|
// Special case handling of Game.Mod argument: if it matches a real filesystem path
|
||||||
// then we use this to override the mod search path, and replace it with the mod id
|
// then we use this to override the mod search path, and replace it with the mod id
|
||||||
|
|||||||
Reference in New Issue
Block a user