This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved logging facilities, improved game traversal efficiency
- Loading branch information
Showing
13 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
namespace Ficdown.Parser | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public class Logger | ||
{ | ||
private static bool _initialized = false; | ||
private static bool _debug = false; | ||
private static Dictionary<Type, Logger> _cache; | ||
|
||
public Type Type { get; private set; } | ||
|
||
private Logger(Type type) | ||
{ | ||
Type = type; | ||
} | ||
|
||
public static void Initialize(bool debug) | ||
{ | ||
_debug = debug; | ||
_cache = new Dictionary<Type, Logger>(); | ||
_initialized = true; | ||
} | ||
|
||
public static Logger GetLogger<T>() | ||
{ | ||
var type = typeof(T); | ||
lock(_cache) | ||
{ | ||
if(!_cache.ContainsKey(type)) | ||
_cache.Add(type, new Logger(type)); | ||
} | ||
return _cache[type]; | ||
} | ||
|
||
private string Decorate(string message) | ||
{ | ||
return $"{DateTime.Now.ToString("")} <{Type.Name}> {message}"; | ||
} | ||
|
||
public void Raw(string message) | ||
{ | ||
Console.WriteLine(message); | ||
} | ||
|
||
public void Log(string message) | ||
{ | ||
Raw(Decorate(message)); | ||
} | ||
|
||
public void Debug(string message) | ||
{ | ||
if(!_debug) return; | ||
Log($"DEBUG: {message}"); | ||
} | ||
|
||
public void Error(string message, Exception ex = null) | ||
{ | ||
Console.Error.WriteLine(Decorate($"ERROR: {message}")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.