Restructured logging in tools.
This commit is contained in:
parent
b744ae653c
commit
7d418a75ff
@ -16,7 +16,7 @@ namespace SlatedGameToolkit.Tools.CommandSystem
|
|||||||
this.commandMap = commands;
|
this.commandMap = commands;
|
||||||
}
|
}
|
||||||
public void Process(IInteractable interactable) {
|
public void Process(IInteractable interactable) {
|
||||||
string message = interactable.Listen();
|
string message = interactable.Listen().ToLower();
|
||||||
string[] splitMessage = message.Split(' ');
|
string[] splitMessage = message.Split(' ');
|
||||||
string invocation = splitMessage[0];
|
string invocation = splitMessage[0];
|
||||||
|
|
||||||
|
@ -3,10 +3,12 @@ using SlatedGameToolkit.Framework.Logging;
|
|||||||
|
|
||||||
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
||||||
{
|
{
|
||||||
public class ConsoleInteraction : IInteractable, ILogListener
|
public class ConsoleInteraction : IInteractable
|
||||||
{
|
{
|
||||||
private volatile bool listening;
|
private volatile bool listening;
|
||||||
|
public bool Listening { get {return listening;}}
|
||||||
string prefix;
|
string prefix;
|
||||||
|
public string Prefix {get {return prefix;}}
|
||||||
public bool Debug { get; set; }
|
public bool Debug { get; set; }
|
||||||
public LogLevel Level => Debug ? LogLevel.DEBUG : LogLevel.INFO;
|
public LogLevel Level => Debug ? LogLevel.DEBUG : LogLevel.INFO;
|
||||||
|
|
||||||
@ -33,15 +35,5 @@ namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
|||||||
Console.SetCursorPosition(0, Console.CursorTop);
|
Console.SetCursorPosition(0, Console.CursorTop);
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LogMesesage(string message, DateTime time, LogLevel level)
|
|
||||||
{
|
|
||||||
Console.SetCursorPosition(0, Console.CursorTop);
|
|
||||||
Console.WriteLine(string.Format("Playground [{0}] [{1}]: {2}", level, time.ToString("H:mm:ss"), message));
|
|
||||||
if (listening) {
|
|
||||||
Console.SetCursorPosition(0, Console.CursorTop);
|
|
||||||
Console.Write(prefix + "> ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +1,10 @@
|
|||||||
using SlatedGameToolkit.Framework.Logging;
|
|
||||||
|
|
||||||
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
||||||
{
|
{
|
||||||
public interface IInteractable : ILogListener
|
public interface IInteractable
|
||||||
{
|
{
|
||||||
void Tell(string message);
|
void Tell(string message);
|
||||||
void Separate();
|
void Separate();
|
||||||
string Listen();
|
string Listen();
|
||||||
|
public bool Listening { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using SlatedGameToolkit.Framework.Logging;
|
|
||||||
using SlatedGameToolkit.Tools.CommandSystem.Exceptions;
|
using SlatedGameToolkit.Tools.CommandSystem.Exceptions;
|
||||||
|
|
||||||
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
||||||
@ -12,7 +11,7 @@ namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
|||||||
this.oneTime = oneTime;
|
this.oneTime = oneTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogLevel Level => LogLevel.DEBUG;
|
public bool Listening => false;
|
||||||
|
|
||||||
public string Listen()
|
public string Listen()
|
||||||
{
|
{
|
||||||
@ -21,12 +20,6 @@ namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
|||||||
return oneTime;
|
return oneTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LogMesesage(string message, DateTime time, LogLevel level)
|
|
||||||
{
|
|
||||||
Console.SetCursorPosition(0, Console.CursorTop);
|
|
||||||
Console.WriteLine(string.Format("Game Engine [{0}] [{1}]: \n{2}", level, time.ToString(), message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Separate()
|
public void Separate()
|
||||||
{
|
{
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
@ -10,6 +10,8 @@ namespace SlatedGameToolkit.Tools.Commands
|
|||||||
public class GraphicalPlaygroundCommand : IInvocable
|
public class GraphicalPlaygroundCommand : IInvocable
|
||||||
{
|
{
|
||||||
private readonly string[] invokers = new string[] {"playground"};
|
private readonly string[] invokers = new string[] {"playground"};
|
||||||
|
private ConsoleLogListener logListener;
|
||||||
|
private bool debugging;
|
||||||
|
|
||||||
public bool Execute(IInteractable interactable, string[] args)
|
public bool Execute(IInteractable interactable, string[] args)
|
||||||
{
|
{
|
||||||
@ -20,7 +22,8 @@ namespace SlatedGameToolkit.Tools.Commands
|
|||||||
interactable.Tell("Engine is already running!");
|
interactable.Tell("Engine is already running!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Logger.AddLogListener(interactable);
|
Logger.AddLogListener((logListener = new ConsoleLogListener(interactable as ConsoleInteraction)));
|
||||||
|
logListener.Debug = debugging;
|
||||||
GameEngine.Ignite(new MainState());
|
GameEngine.Ignite(new MainState());
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].Equals("stop")) {
|
} else if (args[0].Equals("stop")) {
|
||||||
@ -28,12 +31,23 @@ namespace SlatedGameToolkit.Tools.Commands
|
|||||||
interactable.Tell("Engine was never running!");
|
interactable.Tell("Engine was never running!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Logger.RemoveLogListener(logListener);
|
||||||
GameEngine.Stop();
|
GameEngine.Stop();
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].Equals("status")) {
|
} else if (args[0].Equals("status")) {
|
||||||
interactable.Tell("Running: " + GameEngine.IsRunning());
|
interactable.Tell("Running: " + GameEngine.IsRunning());
|
||||||
interactable.Tell("Target FPS: " + (GameEngine.targetFPS <= 0 ? "Not bounded." : GameEngine.targetFPS.ToString()));
|
interactable.Tell("Target FPS: " + (GameEngine.targetFPS <= 0 ? "Not bounded." : GameEngine.targetFPS.ToString()));
|
||||||
interactable.Tell("Update Step: " + (GameEngine.UpdatesPerSecond <= 0 ? "Not Locked." : GameEngine.UpdatesPerSecond.ToString()));
|
interactable.Tell("Update Step: " + (GameEngine.UpdatesPerSecond <= 0 ? "Not Locked." : GameEngine.UpdatesPerSecond.ToString()));
|
||||||
|
interactable.Tell("Debug logging: " + logListener.Debug);
|
||||||
|
return true;
|
||||||
|
} else if (args[0].Equals("debug")) {
|
||||||
|
debugging = !debugging;
|
||||||
|
if (logListener != null) {
|
||||||
|
logListener.Debug = debugging;
|
||||||
|
interactable.Tell("Debug logging: " + logListener.Debug);
|
||||||
|
} else {
|
||||||
|
interactable.Tell(string.Format("Debug will be turned {0} when playground is started.", debugging ? "on" : "off"));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using SlatedGameToolkit.Framework.Logging;
|
||||||
|
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
|
||||||
|
|
||||||
|
namespace SlatedGameToolkit.Tools.Utilities.Playground
|
||||||
|
{
|
||||||
|
public class ConsoleLogListener : ILogListener
|
||||||
|
{
|
||||||
|
|
||||||
|
public bool Debug { get; set; }
|
||||||
|
public LogLevel Level => Debug ? LogLevel.DEBUG : LogLevel.INFO;
|
||||||
|
private ConsoleInteraction interaction;
|
||||||
|
|
||||||
|
public ConsoleLogListener(ConsoleInteraction interaction = null) {
|
||||||
|
this.interaction = interaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogMesesage(string message, DateTime time, LogLevel level)
|
||||||
|
{
|
||||||
|
Console.SetCursorPosition(0, Console.CursorTop);
|
||||||
|
Console.WriteLine(string.Format("Playground [{0}] [{1}]: {2}", level, time.ToString("H:mm:ss"), message));
|
||||||
|
if (interaction != null && interaction.Listening) {
|
||||||
|
Console.SetCursorPosition(0, Console.CursorTop);
|
||||||
|
Console.Write(interaction.Prefix + "> ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user