feat(Logger)!: add StopLogger function (closes channel)

This commit is contained in:
2024-12-11 12:19:09 +01:00
parent dee54fd93e
commit 72df0b6343
4 changed files with 12 additions and 0 deletions

View File

@@ -20,6 +20,10 @@ func (logger *ConsoleLoggerImpl) StartLogger() {
}) })
} }
func (logger *ConsoleLoggerImpl) StopLogger() {
close(logger.messages)
}
func (logger *ConsoleLoggerImpl) Write(message string) { func (logger *ConsoleLoggerImpl) Write(message string) {
logger.messages <- time.Now().Format(time.UnixDate) + " : " + message + "\n" logger.messages <- time.Now().Format(time.UnixDate) + " : " + message + "\n"
} }

View File

@@ -68,6 +68,10 @@ func (logger *FileLoggerImpl) StartLogger() {
// logger.mutex.Unlock() // logger.mutex.Unlock()
} }
func (logger *FileLoggerImpl) StopLogger() {
close(logger.messages)
}
func (logger *FileLoggerImpl) Write(message string) { func (logger *FileLoggerImpl) Write(message string) {
logger.messages <- time.Now().Format(time.UnixDate) + " : " + message + "\n" logger.messages <- time.Now().Format(time.UnixDate) + " : " + message + "\n"
} }

View File

@@ -20,6 +20,7 @@ type (
init() init()
// Start an infinite loop to write out messages from the channel // Start an infinite loop to write out messages from the channel
StartLogger() StartLogger()
StopLogger()
Write(message string) Write(message string)
WriteRequest(message string, uuid string) WriteRequest(message string, uuid string)
// If an error that is not nill passed in it logs the error and returns 1, otherwise 0 // If an error that is not nill passed in it logs the error and returns 1, otherwise 0
@@ -32,6 +33,7 @@ type (
init() init()
// Start an infinite loop to write out messages from the channel // Start an infinite loop to write out messages from the channel
StartLogger() StartLogger()
StopLogger()
WriteDebug(message string) WriteDebug(message string)
WriteRequestDebug(message string, uuid string) WriteRequestDebug(message string, uuid string)
WriteErrDebug(err error) (errnum int) WriteErrDebug(err error) (errnum int)

View File

@@ -4,6 +4,8 @@ func (lgr *NullLoggerImpl) init() {}
func (logger *NullLoggerImpl) StartLogger() {} func (logger *NullLoggerImpl) StartLogger() {}
func (logger *NullLoggerImpl) StopLogger() {}
func (logger *NullLoggerImpl) Write(message string) {} func (logger *NullLoggerImpl) Write(message string) {}
func (logger *NullLoggerImpl) WriteRequest(message string, request string) {} func (logger *NullLoggerImpl) WriteRequest(message string, request string) {}