disable default log timestamp

This commit is contained in:
2023-05-18 13:34:54 +02:00
parent bc578cf25c
commit 5ea1af7fb1
3 changed files with 520 additions and 495 deletions

View File

@@ -13,26 +13,37 @@ import (
"time"
)
var messageWriter io.Writer = os.Stdout
var accessWriter io.Writer = os.Stdout
var (
messageWriter io.Writer = os.Stdout
accessWriter io.Writer = os.Stdout
logTimestamp bool = false
)
func getLogStamp() string {
var stamp string
if logTimestamp {
stamp = time.Now().Format(time.RFC3339)
}
return stamp
}
func logDebug(messages ...any) {
stamp := time.Now().Format(time.RFC3339)
stamp := getLogStamp()
fmt.Fprintln(messageWriter, stamp, "debug", messages)
}
func logInfo(messages ...any) {
stamp := time.Now().Format(time.RFC3339)
stamp := getLogStamp()
fmt.Fprintln(messageWriter, stamp, "info", messages)
}
func logError(messages ...any) {
stamp := time.Now().Format(time.RFC3339)
stamp := getLogStamp()
fmt.Fprintln(messageWriter, stamp, "error", messages)
}
func logAccess(messages ...any) {
stamp := time.Now().Format(time.RFC3339)
stamp := getLogStamp()
fmt.Fprintln(accessWriter, stamp, "access", messages)
}
@@ -43,3 +54,8 @@ func SetAccessWriter(writer io.Writer) {
func SetMessageWriter(writer io.Writer) {
messageWriter = writer
}
func EnableLogTimestamp(enable bool) {
logTimestamp = enable
}