wip new cfg params
This commit is contained in:
parent
44b25ed9d5
commit
2e8fa14df9
7 changed files with 141 additions and 49 deletions
70
printing.go
Normal file
70
printing.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
||||
/////////////
|
||||
|
||||
func printErrf(format string, args ...interface{}) {
|
||||
if config.LogLevel >= 1 {
|
||||
logMessage("ERROR", fmt.Sprintf(format, args...))
|
||||
}
|
||||
}
|
||||
|
||||
func printWarnf(format string, args ...interface{}) {
|
||||
if config.LogLevel >= 2 {
|
||||
logMessage("WARN", fmt.Sprintf(format, args...))
|
||||
}
|
||||
}
|
||||
|
||||
func printInfof(format string, args ...interface{}) {
|
||||
if config.LogLevel >= 3 {
|
||||
logMessage("INFO", fmt.Sprintf(format, args...))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue