add SDL logger implementation

This commit is contained in:
Gered 2013-08-15 18:45:24 -04:00
parent 42db6d83ae
commit e766bbf7bc
2 changed files with 51 additions and 0 deletions

View file

@ -47,6 +47,7 @@
<Compile Include="Input\SDLKeyboard.cs" />
<Compile Include="Input\SDLMouse.cs" />
<Compile Include="IO\SDLFileSystem.cs" />
<Compile Include="SDLLogger.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

View file

@ -0,0 +1,50 @@
using System;
using System.Text;
namespace Blarg.GameFramework
{
public class SDLLogger : IPlatformLogger
{
StringBuilder _sb;
public SDLLogger()
{
_sb = new StringBuilder(8192);
}
public void Info(string category, string format, params object[] args)
{
WriteLine("INFO", category, format, args);
}
public void Warn(string category, string format, params object[] args)
{
WriteLine("WARN", category, format, args);
}
public void Error(string category, string format, params object[] args)
{
WriteLine("ERROR", category, format, args);
}
public void Debug(string category, string format, params object[] args)
{
WriteLine("DEBUG", category, format, args);
}
private void WriteLine(string tag, string category, string format, params object[] args)
{
_sb.Clear();
var date = DateTime.Now;
_sb.AppendFormat("[{0:00}:{1:00}:{2:00},{3:000}] ", date.Hour, date.Minute, date.Second, date.Millisecond);
_sb.AppendFormat("[{0}] [{1}] ", tag, category);
_sb.AppendFormat(format, args);
_sb.Append(Environment.NewLine);
Console.Write(_sb.ToString());
}
}
}