Extend log_ext with better max level handling and console output

This commit is contained in:
René Linder 2022-02-21 08:23:36 +01:00
parent b11846a3af
commit 5e8359cdc1

View file

@ -35,8 +35,10 @@ CompilerEndIf
DeclareModule lhs_log_ext
Global.s App_Name = "lhs_ext_Logger"
#Debug = 1
#NoDebug = 0
#Debug = #True
#NoDebug = #False
#Console = #True
#NoConsole = #False
Structure LogThreads
Logger_UUID.s
@ -54,6 +56,7 @@ DeclareModule lhs_log_ext
LogFileDateFormat.s
LogDateFormat.s
debugger.i
console.i
List Messages.s()
EndStructure
@ -61,10 +64,13 @@ DeclareModule lhs_log_ext
Global NewList LoggerUUID.s()
Enumeration LogLevel
#Info
#Warning
#NoLog
#Error
#Warning
#Info
#Debug
EndEnumeration
Declare IsCreated(UUID.s)
Declare SetLogFile(UUID.s, LogFileName.s)
Declare SetMaxSize(UUID.s, Megabyte.i)
@ -83,6 +89,7 @@ Module lhs_log_ext
XIncludeFile "lhs_uuid.pbi"
Global CreateLoggerMutex.i = CreateMutex()
Global ConsoleMutex.i = CreateMutex()
Procedure.s Create(Name.s)
Define.s InternalUUID
@ -102,6 +109,7 @@ Module lhs_log_ext
Logger(InternalUUID)\LogLevel.i = #Info
Logger(InternalUUID)\LogFileDateFormat.s = "%yyyy_%mm_%dd_%hh_%ii_%ss"
Logger(InternalUUID)\LogDateFormat.s = "%yyyy.%mm.%dd %hh:%ii:%ss"
Logger(InternalUUID)\console = #NoConsole
UnlockMutex(CreateLoggerMutex)
ProcedureReturn InternalUUID
EndIf
@ -271,7 +279,15 @@ Module lhs_log_ext
EndProcedure
Procedure Out(UUID.s, ToLog.s, debugger.i = #NoDebug)
Procedure OutPutConsole(ToLog.s)
;Hardlock ConsoleOutput
If LockMutex(ConsoleMutex)
PrintN(ToLog)
UnlockMutex(ConsoleMutex)
EndIf
EndProcedure
Procedure Out(UUID.s, ToLog.s)
If IsCreated(UUID)
LockMutex(Logger(UUID)\Mutex)
LastElement(Logger(UUID)\Messages())
@ -280,14 +296,17 @@ Module lhs_log_ext
If Logger(UUID)\debugger = #Debug
Debug ToLog
EndIf
If Logger(UUID)\console = #Console
OutPutConsole(ToLog)
EndIf
UnlockMutex(Logger(UUID)\Mutex)
SignalSemaphore(Logger(UUID)\WorkerSemaphore)
EndIf
EndProcedure
Procedure OutL(UUID.s, LogType.i, ToLog.s, debugger.i = #NoDebug)
Procedure OutL(UUID.s, LogType.i, ToLog.s)
If IsCreated(UUID)
If LogType >= LogLevel
If LogType <= Logger(UUID)\LogLevel
Select LogType
Case #Info
ToLog = "Info: " + ToLog
@ -299,6 +318,7 @@ Module lhs_log_ext
ToLog = "Error: " + ToLog
EndSelect
Out(UUID, ToLog, debugger)
ProcedureReturn #True
EndIf
EndIf
EndProcedure