Extend log_ext with better max level handling and console output
This commit is contained in:
parent
b11846a3af
commit
5e8359cdc1
1 changed files with 27 additions and 7 deletions
|
@ -35,8 +35,10 @@ CompilerEndIf
|
||||||
|
|
||||||
DeclareModule lhs_log_ext
|
DeclareModule lhs_log_ext
|
||||||
Global.s App_Name = "lhs_ext_Logger"
|
Global.s App_Name = "lhs_ext_Logger"
|
||||||
#Debug = 1
|
#Debug = #True
|
||||||
#NoDebug = 0
|
#NoDebug = #False
|
||||||
|
#Console = #True
|
||||||
|
#NoConsole = #False
|
||||||
|
|
||||||
Structure LogThreads
|
Structure LogThreads
|
||||||
Logger_UUID.s
|
Logger_UUID.s
|
||||||
|
@ -54,6 +56,7 @@ DeclareModule lhs_log_ext
|
||||||
LogFileDateFormat.s
|
LogFileDateFormat.s
|
||||||
LogDateFormat.s
|
LogDateFormat.s
|
||||||
debugger.i
|
debugger.i
|
||||||
|
console.i
|
||||||
List Messages.s()
|
List Messages.s()
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
|
@ -61,10 +64,13 @@ DeclareModule lhs_log_ext
|
||||||
Global NewList LoggerUUID.s()
|
Global NewList LoggerUUID.s()
|
||||||
|
|
||||||
Enumeration LogLevel
|
Enumeration LogLevel
|
||||||
#Info
|
#NoLog
|
||||||
#Warning
|
|
||||||
#Error
|
#Error
|
||||||
|
#Warning
|
||||||
|
#Info
|
||||||
|
#Debug
|
||||||
EndEnumeration
|
EndEnumeration
|
||||||
|
|
||||||
Declare IsCreated(UUID.s)
|
Declare IsCreated(UUID.s)
|
||||||
Declare SetLogFile(UUID.s, LogFileName.s)
|
Declare SetLogFile(UUID.s, LogFileName.s)
|
||||||
Declare SetMaxSize(UUID.s, Megabyte.i)
|
Declare SetMaxSize(UUID.s, Megabyte.i)
|
||||||
|
@ -83,6 +89,7 @@ Module lhs_log_ext
|
||||||
XIncludeFile "lhs_uuid.pbi"
|
XIncludeFile "lhs_uuid.pbi"
|
||||||
|
|
||||||
Global CreateLoggerMutex.i = CreateMutex()
|
Global CreateLoggerMutex.i = CreateMutex()
|
||||||
|
Global ConsoleMutex.i = CreateMutex()
|
||||||
|
|
||||||
Procedure.s Create(Name.s)
|
Procedure.s Create(Name.s)
|
||||||
Define.s InternalUUID
|
Define.s InternalUUID
|
||||||
|
@ -102,6 +109,7 @@ Module lhs_log_ext
|
||||||
Logger(InternalUUID)\LogLevel.i = #Info
|
Logger(InternalUUID)\LogLevel.i = #Info
|
||||||
Logger(InternalUUID)\LogFileDateFormat.s = "%yyyy_%mm_%dd_%hh_%ii_%ss"
|
Logger(InternalUUID)\LogFileDateFormat.s = "%yyyy_%mm_%dd_%hh_%ii_%ss"
|
||||||
Logger(InternalUUID)\LogDateFormat.s = "%yyyy.%mm.%dd %hh:%ii:%ss"
|
Logger(InternalUUID)\LogDateFormat.s = "%yyyy.%mm.%dd %hh:%ii:%ss"
|
||||||
|
Logger(InternalUUID)\console = #NoConsole
|
||||||
UnlockMutex(CreateLoggerMutex)
|
UnlockMutex(CreateLoggerMutex)
|
||||||
ProcedureReturn InternalUUID
|
ProcedureReturn InternalUUID
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -271,7 +279,15 @@ Module lhs_log_ext
|
||||||
|
|
||||||
EndProcedure
|
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)
|
If IsCreated(UUID)
|
||||||
LockMutex(Logger(UUID)\Mutex)
|
LockMutex(Logger(UUID)\Mutex)
|
||||||
LastElement(Logger(UUID)\Messages())
|
LastElement(Logger(UUID)\Messages())
|
||||||
|
@ -280,14 +296,17 @@ Module lhs_log_ext
|
||||||
If Logger(UUID)\debugger = #Debug
|
If Logger(UUID)\debugger = #Debug
|
||||||
Debug ToLog
|
Debug ToLog
|
||||||
EndIf
|
EndIf
|
||||||
|
If Logger(UUID)\console = #Console
|
||||||
|
OutPutConsole(ToLog)
|
||||||
|
EndIf
|
||||||
UnlockMutex(Logger(UUID)\Mutex)
|
UnlockMutex(Logger(UUID)\Mutex)
|
||||||
SignalSemaphore(Logger(UUID)\WorkerSemaphore)
|
SignalSemaphore(Logger(UUID)\WorkerSemaphore)
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure OutL(UUID.s, LogType.i, ToLog.s, debugger.i = #NoDebug)
|
Procedure OutL(UUID.s, LogType.i, ToLog.s)
|
||||||
If IsCreated(UUID)
|
If IsCreated(UUID)
|
||||||
If LogType >= LogLevel
|
If LogType <= Logger(UUID)\LogLevel
|
||||||
Select LogType
|
Select LogType
|
||||||
Case #Info
|
Case #Info
|
||||||
ToLog = "Info: " + ToLog
|
ToLog = "Info: " + ToLog
|
||||||
|
@ -299,6 +318,7 @@ Module lhs_log_ext
|
||||||
ToLog = "Error: " + ToLog
|
ToLog = "Error: " + ToLog
|
||||||
EndSelect
|
EndSelect
|
||||||
Out(UUID, ToLog, debugger)
|
Out(UUID, ToLog, debugger)
|
||||||
|
ProcedureReturn #True
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
Loading…
Reference in a new issue