mirror of
https://github.com/akpaevj/executor-scripts.git
synced 2024-11-24 08:52:35 +02:00
72 lines
1.6 KiB
Plaintext
72 lines
1.6 KiB
Plaintext
#required ConsoleHelper.sbsl
|
|
|
|
enum LogLevel
|
|
Trace,
|
|
Debug,
|
|
Information,
|
|
Warning,
|
|
Error,
|
|
Critical,
|
|
None
|
|
;
|
|
|
|
@Global
|
|
method t(Message: String)
|
|
Log(LogLevel.Trace, Message)
|
|
;
|
|
|
|
@Global
|
|
method d(Message: String)
|
|
Log(LogLevel.Debug, Message)
|
|
;
|
|
|
|
@Global
|
|
method i(Message: String)
|
|
Log(LogLevel.Information, Message)
|
|
;
|
|
|
|
@Global
|
|
method w(Message: String)
|
|
Log(LogLevel.Warning, Message)
|
|
;
|
|
|
|
@Global
|
|
method e(Message: String, ThrowException = False)
|
|
Log(LogLevel.Error, Message, ThrowException)
|
|
;
|
|
|
|
@Global
|
|
method c(Message: String, ThrowException = False)
|
|
Log(LogLevel.Critical, Message, ThrowException)
|
|
;
|
|
|
|
method Log(Level: LogLevel, Message: String, ThrowException = False)
|
|
var LevelString = ""
|
|
|
|
case Level
|
|
when LogLevel.Trace
|
|
LevelString = "TRACE"
|
|
when LogLevel.Debug
|
|
LevelString = "DEBUG"
|
|
when LogLevel.Information
|
|
LevelString = ThrowException ? "INFO" : ConsoleHelper.SetColor("INFO", 32)
|
|
when LogLevel.Warning
|
|
LevelString = ThrowException ? "WARN" : ConsoleHelper.SetColor("WARN", 33)
|
|
when LogLevel.Error
|
|
LevelString = ThrowException ? "ERROR" : ConsoleHelper.SetColor("ERROR", 31)
|
|
when LogLevel.Critical
|
|
LevelString = ThrowException ? "CRIT" : ConsoleHelper.SetColor("CRIT", 41)
|
|
;
|
|
|
|
val Content = "${DateTime.Now()} - %LevelString - %Message"
|
|
|
|
if Level.Index >= LogLevel.Error.Index
|
|
if ThrowException
|
|
throw new IllegalStateException(Content)
|
|
else
|
|
Console.WriteError(Content)
|
|
;
|
|
else
|
|
Console.Write(Content)
|
|
;
|
|
; |