Hey guys, I have recently added a logger that you can utilize in your scripts. In the future, I may add more features such as saving the logs to a file, taking automatic screen shots on Error or Fatals, allowing custom formatting and what not. But for now, here is what it can do.
- Logs at Debug, Status, Warn, Error, and Fatal levels.
- The Fatal level terminates the script.
- Allows you to specify the lowest level that should be displayed. (So, if the lowest level is set to Error, only Errors and Fatals will be logged!)
- Allows you to specify the logger's name. The name will appear in every log made by that logger.
- Every log contains a time stamp.
The usage is relatively simple. Just initialize a logger and have fun logging!
Simba Code:
{$DEFINE SMART}
{$i Reflection/Reflection.simba}
var MyLogger: TReflectLogger;
begin
MyLogger.Init('MyScript');
MyLogger.Debug('This debug message should not be printed.');
MyLogger.Status('I can use %s!', ['formatting']);
MyLogger.Level := TReflectLoggerLevel.Debug;
MyLogger.Debug('This debug message should be printed.');
MyLogger.Warn('Please ask %d questions if you have %s.', [RandomRange(1, 5), 'them']);
MyLogger.Fatal('A Fatal log will cause the script to terminate.');
MyLogger.Error('The script should have terminated!');
end.
Code:
[02:00:00:937] [MyScript] [Status] I can use formatting!
[02:00:00:940] [MyScript] [Debug] This debug message should be printed.
[02:00:00:943] [MyScript] [Warn] Please ask 4 questions if you have them.
[02:00:00:946] [MyScript] [Fatal] A Fatal log will cause the script to terminate.
Successfully executed.