2024-01-02 15:38:51 +08:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-04-08 19:03:20 +08:00
|
|
|
"fmt"
|
2024-03-26 15:27:24 +08:00
|
|
|
"sync"
|
2024-01-02 15:38:51 +08:00
|
|
|
)
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// kisDefaultLog Default provided log object
|
2024-04-15 11:17:47 +08:00
|
|
|
type kisDefaultLog struct {
|
|
|
|
debugMode bool
|
|
|
|
mu sync.Mutex
|
2024-03-26 15:27:24 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 11:17:47 +08:00
|
|
|
func (log *kisDefaultLog) SetDebugMode(enable bool) {
|
|
|
|
log.mu.Lock()
|
|
|
|
defer log.mu.Unlock()
|
|
|
|
log.debugMode = enable
|
2024-01-02 15:38:51 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 11:17:47 +08:00
|
|
|
func (log *kisDefaultLog) InfoF(str string, v ...interface{}) {
|
|
|
|
fmt.Printf(str, v...)
|
|
|
|
fmt.Printf("\n")
|
2024-04-07 12:02:02 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 11:17:47 +08:00
|
|
|
func (log *kisDefaultLog) ErrorF(str string, v ...interface{}) {
|
|
|
|
fmt.Printf(str, v...)
|
|
|
|
fmt.Printf("\n")
|
2024-01-02 15:38:51 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 11:17:47 +08:00
|
|
|
func (log *kisDefaultLog) DebugF(str string, v ...interface{}) {
|
|
|
|
log.mu.Lock()
|
|
|
|
defer log.mu.Unlock()
|
|
|
|
if log.debugMode {
|
|
|
|
fmt.Printf(str, v...)
|
|
|
|
fmt.Printf("\n")
|
2024-03-26 15:27:24 +08:00
|
|
|
}
|
2024-01-02 15:38:51 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 11:17:47 +08:00
|
|
|
func (log *kisDefaultLog) InfoFX(ctx context.Context, str string, v ...interface{}) {
|
|
|
|
fmt.Println(ctx)
|
|
|
|
fmt.Printf(str, v...)
|
|
|
|
fmt.Printf("\n")
|
2024-01-02 15:38:51 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 11:17:47 +08:00
|
|
|
func (log *kisDefaultLog) ErrorFX(ctx context.Context, str string, v ...interface{}) {
|
|
|
|
fmt.Println(ctx)
|
|
|
|
fmt.Printf(str, v...)
|
|
|
|
fmt.Printf("\n")
|
2024-01-02 15:38:51 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 11:17:47 +08:00
|
|
|
func (log *kisDefaultLog) DebugFX(ctx context.Context, str string, v ...interface{}) {
|
|
|
|
log.mu.Lock()
|
|
|
|
defer log.mu.Unlock()
|
|
|
|
if log.debugMode {
|
|
|
|
fmt.Println(ctx)
|
|
|
|
fmt.Printf(str, v...)
|
|
|
|
fmt.Printf("\n")
|
2024-03-26 15:27:24 +08:00
|
|
|
}
|
2024-04-08 19:03:20 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 11:17:47 +08:00
|
|
|
func init() {
|
2024-04-15 17:50:02 +08:00
|
|
|
// If no logger is set, use the default kisDefaultLog object at startup
|
2024-04-15 11:17:47 +08:00
|
|
|
if Logger() == nil {
|
|
|
|
SetLogger(&kisDefaultLog{})
|
2024-01-02 15:38:51 +08:00
|
|
|
}
|
|
|
|
}
|