initial commit
This commit is contained in:
commit
e204e5538d
25 changed files with 578 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
build/
|
||||
recovery/
|
||||
BeefSpace_User.toml
|
9
BeefProj.toml
Normal file
9
BeefProj.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
FileVersion = 1
|
||||
|
||||
[Project]
|
||||
Name = "LybLog"
|
||||
TargetType = "BeefLib"
|
||||
StartupObject = "LybLog.Program"
|
||||
|
||||
[Configs.Debug.Win64]
|
||||
EnvironmentVars = ["LOG_DEBUG"]
|
6
BeefSpace.toml
Normal file
6
BeefSpace.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
FileVersion = 1
|
||||
Projects = {LybLog = {Path = "."}, Tests = {Path = "Tests"}}
|
||||
|
||||
[Workspace]
|
||||
StartupProject = "Tests"
|
||||
PreprocessorMacros = ["LOG_TRACE"]
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2022 Jannis vH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
72
README.md
Normal file
72
README.md
Normal file
|
@ -0,0 +1,72 @@
|
|||
# LybLog - A simple logger for beeflang
|
||||
|
||||
```cs
|
||||
namespace MyProgram;
|
||||
|
||||
using LybLog;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Log.Settings.DoFileLog = true; //Log to a logfile
|
||||
Log.Info("Started the program");
|
||||
Log.Warn("About to close the program");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Table of contents
|
||||
- Installation
|
||||
- Basics
|
||||
- Logging
|
||||
- Log Levels
|
||||
- Preprocessor
|
||||
- Settings
|
||||
- Callbacks
|
||||
- Formatting
|
||||
|
||||
### Installation
|
||||
1. Download or clone the repo to your computer (Move it to your beeflibs folder if you plan on using LybLog in multiple projects)
|
||||
2. Open your project in the BeefIde
|
||||
3. Rightclick on your workspace
|
||||
- Select: "Add from Installed" if it is in your beeflibs folder
|
||||
- Select: "Add existing Project" if it is somehwere else
|
||||
4. Find LybLog in the explorer and select its .toml file
|
||||
5. Rightclick on your project in the workspace
|
||||
6. Go to Properties -> Dependencies and check the box that says LybLog
|
||||
7. In the file you want to use the logger add a using LybLog statement or simply say LybLog.Log.Methodname(Message). You can now use LybLog in your project
|
||||
|
||||
### Basics
|
||||
- LybLog is a singleton and has somewhat resonable default settings, so for its default usage you can simply just call the basic functions and pass in your message and it will work fine for you. The basic functions provided are: Trace, Debug, Info, Warn, Error and Fatal
|
||||
- Log levels or log severity are the importance of what is being logged. LybLog provides 6 common log levels, which are as follows.
|
||||
- Trace: The lowest log level, used to give detailed information about what one specific part of the program is doing.
|
||||
- Debug: Information, such as variable values used to debug the program.
|
||||
- Info: General information about the programs state, like a system that has been loaded sucessfully or wether the program connected to a server.
|
||||
- Warn: Something is not how it is supposed to be but the program can still continue and might be able to ignore it, but might also error in the future.
|
||||
- Error: An error occured and now a part of the program wont execute correctly. It might still be possible to recover from this.
|
||||
- Fatal: An error occured that forces the entire program to stop
|
||||
|
||||
### Preprocessor
|
||||
While you can simply just set your log level to a higher level for release builds, the log level is still a dynamic value so there will always be a check left which might have an impact on the performance of the program. By using a workspace define preprocessor you can set a minimal log level at compile time, which should cause some performance improvements without needing to remove trace calls.
|
||||
|
||||
### Settings
|
||||
The settings object on the logger can be used to set specific settings at runtime.
|
||||
Settings that start with "Do" toggle the thing they are about, such as wether it should log to console or a file
|
||||
Settings also provides a color option for the console, alllows the user to set the logfilepath and has an option to clear the logfile on every new program start.
|
||||
```
|
||||
Log.Settings.DoConsoleLog = true;
|
||||
Log.Settings.DoIdeLog = true;
|
||||
Log.Settings.Colors.Debug = .Blue;
|
||||
Log.Settings.LogFilePath = ".log";
|
||||
```
|
||||
### Callbacks
|
||||
Callbacks are a way for the user to get information back about when something is being logged.
|
||||
Settings has a callback even object which the user can register events to that will be called when a log function is called.
|
||||
```
|
||||
Log.Settings.Callbacks.Add(new => MyMethodName);
|
||||
```
|
||||
The callback itself gets the log level of the message aswell as an unformatted message string and can do with that whatever it wants.
|
||||
|
||||
### Formatter
|
||||
As a user you may need a custom formatter so the settings object also has an IFormatter interface, which you can inherit from to create your own message formatter.
|
6
Tests/BeefProj.toml
Normal file
6
Tests/BeefProj.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
FileVersion = 1
|
||||
Dependencies = {corlib = "*", LybLog = "*"}
|
||||
|
||||
[Project]
|
||||
Name = "Tests"
|
||||
StartupObject = "Tests.Program"
|
18
Tests/src/Features.bf
Normal file
18
Tests/src/Features.bf
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
Feature List:
|
||||
|
||||
-Output to Console
|
||||
-Output
|
||||
-Custom Formatting
|
||||
-Custom Coloring
|
||||
|
||||
-Output to Ide
|
||||
|
||||
-Output to Callbacks
|
||||
|
||||
-Output to files
|
||||
-Cache in cache before outputting
|
||||
-Write to cache when the app closes
|
||||
-Write to cache on fatal
|
||||
-Flush the cache manually
|
||||
*/
|
94
Tests/src/Program.bf
Normal file
94
Tests/src/Program.bf
Normal file
|
@ -0,0 +1,94 @@
|
|||
namespace Tests;
|
||||
using System;
|
||||
using LybLog;
|
||||
class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("First step of testing. All basic logging functions");
|
||||
Log.Trace("This is a trace log");
|
||||
Log.Debug("This is a debug log");
|
||||
Log.Info("This is a info log");
|
||||
Log.Warn("This is a warn log");
|
||||
Log.Error("This is a error log");
|
||||
Log.Fatal("This is a fatal log");
|
||||
Console.ReadLine(.. scope .());
|
||||
|
||||
Console.WriteLine("Second step of testing. Logging to the ide");
|
||||
Log.Settings.DoConsoleLog = false;
|
||||
Log.Settings.DoIdeLog = true;
|
||||
Log.Trace("This is a trace log");
|
||||
Log.Debug("This is a debug log");
|
||||
Log.Info("This is a info log");
|
||||
Log.Warn("This is a warn log");
|
||||
Log.Error("This is a error log");
|
||||
Log.Fatal("This is a fatal log");
|
||||
Console.ReadLine(.. scope .());
|
||||
|
||||
Console.WriteLine("Third step of testing. Logging to a callback");
|
||||
Log.Settings.DoConsoleLog = false;
|
||||
Log.Settings.DoIdeLog = false;
|
||||
Log.Settings.DoCallbackLog = true;
|
||||
Log.Settings.Callbacks.Add(new => CallbackTest);
|
||||
Log.Trace("This is a trace log");
|
||||
Log.Debug("This is a debug log");
|
||||
Log.Info("This is a info log");
|
||||
Log.Warn("This is a warn log");
|
||||
Log.Error("This is a error log");
|
||||
Log.Fatal("This is a fatal log");
|
||||
Console.ReadLine(.. scope .());
|
||||
|
||||
Console.WriteLine("Fourth step of testing. log levels. The followign logs should only show warn or higher");
|
||||
Log.Settings.DoCallbackLog = false;
|
||||
Log.Settings.DoConsoleLog = true;
|
||||
Log.Settings.LogLevel = .Warn;
|
||||
Log.Trace("This is a trace log");
|
||||
Log.Debug("This is a debug log");
|
||||
Log.Info("This is a info log");
|
||||
Log.Warn("This is a warn log");
|
||||
Log.Error("This is a error log");
|
||||
Log.Fatal("This is a fatal log");
|
||||
Console.ReadLine(.. scope .());
|
||||
|
||||
Console.WriteLine("Fith step of testing. Logging to a File");
|
||||
Log.Settings.DoConsoleLog = false;
|
||||
Log.Settings.LogLevel = .Trace;
|
||||
Log.Settings.DoFileLog = true;
|
||||
Log.Settings.LogFilePath = "test.log";
|
||||
Log.Trace("This is a trace log");
|
||||
Log.Debug("This is a debug log");
|
||||
Log.Info("This is a info log");
|
||||
Log.Warn("This is a warn log");
|
||||
Log.Error("This is a error log");
|
||||
Log.Fatal("This is a fatal log");
|
||||
Console.ReadLine(.. scope .());
|
||||
|
||||
Console.WriteLine("Sixth step of testing. Cleaning file upon initialization");
|
||||
Console.WriteLine("The test.log file should now be cleared");
|
||||
Log.Settings.ClearLogFileOnLoad = true;
|
||||
Console.ReadLine(.. scope .());
|
||||
|
||||
Console.WriteLine("Seventh step of testing. File logger caching");
|
||||
Console.WriteLine("The file should still have no contents, since it waits for the cache to be fille");
|
||||
Log.Settings.CacheSize = 3;
|
||||
Log.Settings.DoConsoleLog = true;
|
||||
Log.Trace("This is a trace log");
|
||||
Log.Debug("This is a debug log");
|
||||
Log.Info("This is a info log");
|
||||
Console.WriteLine("It has been logged but no contents are in the file");
|
||||
Console.ReadLine(.. scope .());
|
||||
Log.Warn("This is a warn log");
|
||||
Log.Error("This is a error log");
|
||||
Console.WriteLine("Warn should be logged but error shouldnt due to cache sizes");
|
||||
Console.WriteLine("Once fatal is logged it should be though, since fatal forces a cache empty");
|
||||
Console.ReadLine(.. scope .());
|
||||
Log.Fatal("This is a fatal log");
|
||||
Console.ReadLine(.. scope .());
|
||||
|
||||
}
|
||||
|
||||
public static void CallbackTest(LogLevel p, String pMessage)
|
||||
{
|
||||
Console.WriteLine(scope $"{p.ToString(.. scope .())} This is a callback: {pMessage}");
|
||||
}
|
||||
}
|
6
Tests/test.log
Normal file
6
Tests/test.log
Normal file
|
@ -0,0 +1,6 @@
|
|||
[12/19/2022 10:46:54 AM]:[TRACE]:This is a trace log
|
||||
[12/19/2022 10:46:54 AM]:[DEBUG3]:This is a debug log
|
||||
[12/19/2022 10:46:54 AM]:[INFO]:This is a info log
|
||||
[12/19/2022 10:46:57 AM]:[WARN]:This is a warn log
|
||||
[12/19/2022 10:46:57 AM]:[ERROR]:This is a error log
|
||||
[12/19/2022 10:46:57 AM]:[FATAL]:This is a fatal log
|
14
src/Acess.bf
Normal file
14
src/Acess.bf
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace LybLog;
|
||||
/*
|
||||
This file creates a global acessor for the logger class,
|
||||
Allowing the user to do Log.Warn and not having to do LybLog.Log.Warn
|
||||
*/
|
||||
|
||||
public static
|
||||
{
|
||||
public static LybLog Log
|
||||
{
|
||||
get { return LybLog.Log; }
|
||||
private set; //Its a singleton so we dont rly want people to set it
|
||||
}
|
||||
}
|
29
src/LybLog.bf
Normal file
29
src/LybLog.bf
Normal file
|
@ -0,0 +1,29 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
|
||||
class LybLog
|
||||
{
|
||||
private static LybLog _Object ~ delete _; //Singleton instance goes here
|
||||
public LybLogSettings Settings {get; private set;} = new .() ~ delete _; //Storing the settings in its own class makes the base cleaner
|
||||
private List<String> _Cache = new .() ~ FlushAndDeleteContainerAndItems!(_); //Allows file writes to be done in batches
|
||||
|
||||
//Singleton logic
|
||||
public static LybLog Log
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_Object == null)
|
||||
_Object = new .();
|
||||
return _Object;
|
||||
}
|
||||
private set {}
|
||||
}
|
||||
|
||||
private this() {} //Private constructor so no one else can create this object
|
||||
|
||||
|
||||
|
||||
}
|
13
src/Methods/Private/FlushDeleteContainerAndItems.bf
Normal file
13
src/Methods/Private/FlushDeleteContainerAndItems.bf
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
private mixin FlushAndDeleteContainerAndItems(List<String> pContainer)
|
||||
{
|
||||
Flush();
|
||||
DeleteContainerAndItems!(pContainer);
|
||||
}
|
||||
}
|
29
src/Methods/Private/Log.bf
Normal file
29
src/Methods/Private/Log.bf
Normal file
|
@ -0,0 +1,29 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
private void Log(LogLevel pLL, String pMessage)
|
||||
{
|
||||
var fMessage = Settings.DefaultFormater.Format(pLL, pMessage, .. scope String());
|
||||
|
||||
if(Settings.DoConsoleLog)
|
||||
Console.WriteLine(fMessage);
|
||||
|
||||
if(Settings.DoIdeLog)
|
||||
Debug.WriteLine(fMessage);
|
||||
|
||||
if(Settings.DoCallbackLog && Settings.Callbacks.HasListeners)
|
||||
Settings.Callbacks(pLL, pMessage);
|
||||
|
||||
if(Settings.DoFileLog)
|
||||
{
|
||||
_Cache.Add(new String(fMessage));
|
||||
if(_Cache.Count > Settings.CacheSize)
|
||||
Flush();
|
||||
}
|
||||
Console.ForegroundColor = .White;
|
||||
}
|
||||
}
|
19
src/Methods/Public/Debug.bf
Normal file
19
src/Methods/Public/Debug.bf
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
#if !LOG_DEBUG && !LOG_TRACE
|
||||
[SkipCall]
|
||||
#endif
|
||||
///Variable values needed for debugging
|
||||
public void Debug(String pMessage)
|
||||
{
|
||||
if(Settings.LogLevel.Underlying <= LogLevel.Debug.Underlying)
|
||||
{ //Check wether we should even do this
|
||||
Console.ForegroundColor = Settings.Colors.Debug;
|
||||
Log(.Debug, pMessage);
|
||||
}
|
||||
}
|
||||
}
|
19
src/Methods/Public/Error.bf
Normal file
19
src/Methods/Public/Error.bf
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
#if !LOG_ERROR && !LOG_WARN && !LOG_INFO && !LOG_DEBUG && !LOG_TRACE
|
||||
[SkipCall]
|
||||
#endif
|
||||
///An error in the execution of a specific part of the code, program can still continue
|
||||
public void Error(String pMessage)
|
||||
{
|
||||
if(Settings.LogLevel.Underlying <= LogLevel.Trace.Underlying)
|
||||
{ //Check wether we should even do this
|
||||
Console.ForegroundColor = Settings.Colors.Error;
|
||||
Log(.Error, pMessage);
|
||||
}
|
||||
}
|
||||
}
|
19
src/Methods/Public/Fatal.bf
Normal file
19
src/Methods/Public/Fatal.bf
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
#if !LOG_FATAL && !LOG_ERROR && !LOG_WARN && !LOG_INFO && !LOG_DEBUG && !LOG_TRACE
|
||||
[SkipCall]
|
||||
#endif
|
||||
///Unable to continue executing
|
||||
public void Fatal(String pMessage)
|
||||
{
|
||||
if(Settings.LogLevel.Underlying <= LogLevel.Fatal.Underlying)
|
||||
{ //Check wether we should even do this
|
||||
Console.ForegroundColor = Settings.Colors.Fatal;
|
||||
Log(.Fatal, pMessage);
|
||||
}
|
||||
}
|
||||
}
|
18
src/Methods/Public/Flush.bf
Normal file
18
src/Methods/Public/Flush.bf
Normal file
|
@ -0,0 +1,18 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
///Will write all cached messages to the logfile if logfile is active
|
||||
public void Flush()
|
||||
{
|
||||
for(var i in _Cache)
|
||||
{
|
||||
File.WriteAllText(Settings.LogFilePath, scope $"{i}{Environment.NewLine}",true).IgnoreError();
|
||||
}
|
||||
|
||||
ClearAndDeleteItems(_Cache);
|
||||
}
|
||||
}
|
19
src/Methods/Public/Info.bf
Normal file
19
src/Methods/Public/Info.bf
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
#if !LOG_INFO && !LOG_DEBUG && !LOG_TRACE
|
||||
[SkipCall]
|
||||
#endif
|
||||
///General step information, such as a system being loaded
|
||||
public void Info(String pMessage)
|
||||
{
|
||||
if(Settings.LogLevel.Underlying <= LogLevel.Info.Underlying)
|
||||
{ //Check wether we should even do this
|
||||
Console.ForegroundColor = Settings.Colors.Info;
|
||||
Log(.Info, pMessage);
|
||||
}
|
||||
}
|
||||
}
|
19
src/Methods/Public/Trace.bf
Normal file
19
src/Methods/Public/Trace.bf
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
#if !LOG_TRACE
|
||||
[SkipCall]
|
||||
#endif
|
||||
///Step by step information about the program
|
||||
public void Trace(String pMessage)
|
||||
{
|
||||
if(Settings.LogLevel.Underlying <= LogLevel.Trace.Underlying)
|
||||
{ //Check wether we should even do this
|
||||
Console.ForegroundColor = Settings.Colors.Trace;
|
||||
Log(.Trace, pMessage);
|
||||
}
|
||||
}
|
||||
}
|
19
src/Methods/Public/Warn.bf
Normal file
19
src/Methods/Public/Warn.bf
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
extension LybLog
|
||||
{
|
||||
#if !LOG_WARN && !LOG_INFO && !LOG_DEBUG && !LOG_TRACE
|
||||
[SkipCall]
|
||||
#endif
|
||||
///Unexpected things, that may be problems down the line but could be fixed by the program
|
||||
public void Warn(String pMessage)
|
||||
{
|
||||
if(Settings.LogLevel.Underlying <= LogLevel.Warn.Underlying)
|
||||
{ //Check wether we should even do this
|
||||
Console.ForegroundColor = Settings.Colors.Warn;
|
||||
Log(.Warn, pMessage);
|
||||
}
|
||||
}
|
||||
}
|
8
src/Models/ILoggingFormatter.bf
Normal file
8
src/Models/ILoggingFormatter.bf
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
interface ILoggingFormatter
|
||||
{
|
||||
public void Format(LogLevel pLogLevel, String pMessage, String pFormatedString);
|
||||
}
|
13
src/Models/LogColors.bf
Normal file
13
src/Models/LogColors.bf
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
class LogColors
|
||||
{
|
||||
public ConsoleColor Trace {get; set;} = .Cyan;
|
||||
public ConsoleColor Debug {get; set;} = .Blue;
|
||||
public ConsoleColor Info {get; set;} = .Gray;
|
||||
public ConsoleColor Warn {get; set;} = .Yellow;
|
||||
public ConsoleColor Error {get; set;} = .Red;
|
||||
public ConsoleColor Fatal {get; set;} = .DarkRed;
|
||||
}
|
11
src/Models/LogLevel.bf
Normal file
11
src/Models/LogLevel.bf
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace LybLog;
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
Trace = 0,
|
||||
Debug = 1,
|
||||
Info = 2,
|
||||
Warn = 3,
|
||||
Error = 4,
|
||||
Fatal = 5
|
||||
}
|
69
src/Models/LogSettings.bf
Normal file
69
src/Models/LogSettings.bf
Normal file
|
@ -0,0 +1,69 @@
|
|||
namespace LybLog;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
class LybLogSettings
|
||||
{
|
||||
//General Settings
|
||||
|
||||
///Current log level, only logs of higher priority than this one will be logged
|
||||
public LogLevel LogLevel {get; set;} = .Trace;
|
||||
|
||||
///Event callback for the log message
|
||||
public ref Event<delegate void(LogLevel, String)> Callbacks {get; set;} ~ _.Dispose();
|
||||
|
||||
private String _LogFilePath = new String(".log") ~ delete _;
|
||||
///Path in relation to the executing path where the logfile will be save
|
||||
public String LogFilePath {
|
||||
get
|
||||
{
|
||||
return _LogFilePath;
|
||||
}
|
||||
set
|
||||
{
|
||||
delete _LogFilePath;
|
||||
_LogFilePath = new String(value);
|
||||
}
|
||||
}
|
||||
|
||||
///How many messages should be written to the cache before it dumps into the logfile
|
||||
public uint32 CacheSize {get; set;} = 1;
|
||||
|
||||
///What colors to use for the console output
|
||||
public LogColors Colors {get; set;} = new .() ~ delete _;
|
||||
|
||||
public ILoggingFormatter DefaultFormater {get; set;} = new LoggingFormatter() ~ delete _;
|
||||
//Toggle Settings
|
||||
|
||||
///Should the logger output to the console
|
||||
public bool DoConsoleLog {get; set; } = true;
|
||||
|
||||
///Should the event callbacks be called
|
||||
public bool DoCallbackLog {get; set; } = true;
|
||||
|
||||
///Should the logger output to the ide console
|
||||
public bool DoIdeLog {get; set; } = false;
|
||||
|
||||
///Should the logger write to the logfile
|
||||
public bool DoFileLog {get; set; } = false;
|
||||
|
||||
private bool _ClearLogFileOnLoad = false;
|
||||
///Should the logfile be cleared when the application first writes to it
|
||||
public bool ClearLogFileOnLoad
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ClearLogFileOnLoad;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(value == true)
|
||||
{ //Clear the logfile
|
||||
var res = File.WriteAllText(LogFilePath, "");
|
||||
}
|
||||
|
||||
_ClearLogFileOnLoad = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
25
src/Models/LoggingFormatter.bf
Normal file
25
src/Models/LoggingFormatter.bf
Normal file
|
@ -0,0 +1,25 @@
|
|||
namespace LybLog;
|
||||
|
||||
using System;
|
||||
|
||||
class LoggingFormatter : ILoggingFormatter
|
||||
{
|
||||
void ILoggingFormatter.Format(LogLevel pLogLevel, System.String pMessage, System.String pFormatedString)
|
||||
{
|
||||
switch(pLogLevel)
|
||||
{
|
||||
case .Trace:
|
||||
pFormatedString.Append(scope $"[{DateTime.Now}]:[TRACE]:{pMessage}");
|
||||
case .Debug:
|
||||
pFormatedString.Append(scope $"[{DateTime.Now}]:[DEBUG3]:{pMessage}");
|
||||
case .Info:
|
||||
pFormatedString.Append(scope $"[{DateTime.Now}]:[INFO]:{pMessage}");
|
||||
case .Warn:
|
||||
pFormatedString.Append(scope $"[{DateTime.Now}]:[WARN]:{pMessage}");
|
||||
case .Error:
|
||||
pFormatedString.Append(scope $"[{DateTime.Now}]:[ERROR]:{pMessage}");
|
||||
case .Fatal:
|
||||
pFormatedString.Append(scope $"[{DateTime.Now}]:[FATAL]:{pMessage}");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue