-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4694f59
commit 4bdbd3a
Showing
6 changed files
with
121 additions
and
23 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,55 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using VaettirNet.PixelsDice.Net.Ble; | ||
using VaettirNet.PixelsDice.Net.Interop; | ||
|
||
namespace VaettirNet.PixelsDice.Net; | ||
|
||
public class Logger | ||
{ | ||
public static Logger Instance { get; } = new Logger(); | ||
|
||
private static PixelsLogLevel _logLevel = | ||
#if DEBUG | ||
PixelsLogLevel.Error; | ||
#else | ||
PixelsLogLevel.None; | ||
#endif | ||
|
||
public void Log(PixelsLogLevel level, | ||
FormattableString message, | ||
[CallerFilePath] string file = null, | ||
[CallerLineNumber] int line = 0, | ||
[CallerMemberName] string member = null) | ||
{ | ||
if (!ShouldLog(level)) | ||
{ | ||
return; | ||
} | ||
|
||
// ReSharper disable once ExplicitCallerInfoArgument | ||
Log(level, message.ToString(), file, line, member); | ||
} | ||
|
||
public void Log(PixelsLogLevel level, | ||
string message, | ||
[CallerFilePath] string file = null, | ||
[CallerLineNumber] int line = 0, | ||
[CallerMemberName] string member = null) | ||
{ | ||
if (!ShouldLog(level)) | ||
{ | ||
return; | ||
} | ||
|
||
Console.WriteLine($"[{level}] {file}:{line} in {member}: {message}"); | ||
} | ||
|
||
public bool ShouldLog(PixelsLogLevel level) => level <= _logLevel; | ||
|
||
public static void SetLogLevel(PixelsLogLevel logLevel) | ||
{ | ||
_logLevel = logLevel; | ||
BleManager.SetLogLevel((BleLogLevel)(int)logLevel); | ||
} | ||
} |
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