This repository has been archived by the owner on Dec 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from LokiMidgard/Logger
Logger
- Loading branch information
Showing
3 changed files
with
92 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CodeGeneration.Roslyn | ||
{ | ||
public enum LogLevel | ||
{ | ||
/// <summary> | ||
/// High importance, appears in less verbose logs | ||
/// </summary> | ||
High = 0, | ||
|
||
/// <summary> | ||
/// Normal importance | ||
/// </summary> | ||
Normal = 1, | ||
|
||
/// <summary> | ||
/// Low importance, appears in more verbose logs | ||
/// </summary> | ||
Low = 2, | ||
} | ||
public static class Logger | ||
{ | ||
public static void Log(LogLevel logLevel, string message) | ||
{ | ||
// Prefix every Line with loglevel | ||
var begin = 0; | ||
var end = message.IndexOf('\n'); | ||
bool foundR = end > 0 && message[end - 1] == '\r'; | ||
if(foundR) | ||
end--; | ||
while (end != -1) | ||
{ | ||
Print(message.Substring(begin, end - begin)); | ||
begin = end + (foundR ? 2 : 1); | ||
end = message.IndexOf('\n', begin); | ||
foundR = end > 0 && message[end - 1] == '\r'; | ||
if(foundR) | ||
end--; | ||
} | ||
Print(message.Substring(begin, message.Length - begin)); | ||
|
||
void Print(string toPrint) => Console.WriteLine($"::{logLevel}::{toPrint}"); | ||
} | ||
} | ||
} |