50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// printDebug logs debug-level messages when LogLevel is set to 4.
|
|
func printDebug(format string, args ...interface{}) {
|
|
if config.LogLevel >= 4 {
|
|
logMessage("DEBUG", format, args...)
|
|
}
|
|
}
|
|
|
|
// printInfo logs info-level messages when LogLevel is set to 3 or higher.
|
|
func printInfo(format string, args ...interface{}) {
|
|
if config.LogLevel >= 3 {
|
|
logMessage("INFO", format, args...)
|
|
}
|
|
}
|
|
|
|
// printWarn logs warning-level messages when LogLevel is set to 2 or higher.
|
|
func printWarn(format string, args ...interface{}) {
|
|
if config.LogLevel >= 2 {
|
|
logMessage("WARN", format, args...)
|
|
}
|
|
}
|
|
|
|
// printErr logs error-level messages regardless of LogLevel.
|
|
func printErr(format string, args ...interface{}) {
|
|
if config.LogLevel >= 1 {
|
|
logMessage("ERROR", format, args...)
|
|
}
|
|
}
|
|
|
|
// printMessage logs messages without a specific log level (e.g., general output).
|
|
func printMessage(format string, args ...interface{}) {
|
|
logMessage("", format, args...)
|
|
}
|
|
|
|
// logMessage handles the actual logging logic without using the default logger's timestamp.
|
|
func logMessage(level string, format string, args ...interface{}) {
|
|
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
|
message := fmt.Sprintf(format, args...)
|
|
if level != "" {
|
|
fmt.Printf("[%s %s] %s\n", timestamp, level, message)
|
|
} else {
|
|
fmt.Printf("[%s] %s\n", timestamp, message)
|
|
}
|
|
}
|