mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-14 02:37:25 +01:00
use go logger internally
This commit is contained in:
parent
6f56274ff6
commit
1d0bdd56c7
52
log/log.go
52
log/log.go
@ -8,6 +8,7 @@ package log
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,15 +16,21 @@ var (
|
|||||||
DebugWriter io.Writer = os.Stderr
|
DebugWriter io.Writer = os.Stderr
|
||||||
InfoWriter io.Writer = os.Stderr
|
InfoWriter io.Writer = os.Stderr
|
||||||
WarnWriter io.Writer = os.Stderr
|
WarnWriter io.Writer = os.Stderr
|
||||||
ErrorWriter io.Writer = os.Stderr
|
ErrWriter io.Writer = os.Stderr
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DebugPrefix string = "<7>[DEBUG]"
|
DebugPrefix string = "<7>[DEBUG] "
|
||||||
InfoPrefix string = "<6>[INFO]"
|
InfoPrefix string = "<6>[INFO] "
|
||||||
WarnPrefix string = "<4>[WARNING]"
|
WarnPrefix string = "<4>[WARNING] "
|
||||||
ErrPrefix string = "<3>[ERROR]"
|
ErrPrefix string = "<3>[ERROR] "
|
||||||
FatalPrefix string = "<3>[FATAL]"
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
DebugLog *log.Logger = log.New(DebugWriter, DebugPrefix, 0)
|
||||||
|
InfoLog *log.Logger = log.New(InfoWriter, InfoPrefix, 0)
|
||||||
|
WarnLog *log.Logger = log.New(WarnWriter, WarnPrefix, 0)
|
||||||
|
ErrLog *log.Logger = log.New(ErrWriter, ErrPrefix, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -47,15 +54,13 @@ func init() {
|
|||||||
|
|
||||||
func Debug(v ...interface{}) {
|
func Debug(v ...interface{}) {
|
||||||
if DebugWriter != io.Discard {
|
if DebugWriter != io.Discard {
|
||||||
v = append([]interface{}{DebugPrefix}, v...)
|
DebugLog.Print(v...)
|
||||||
fmt.Fprintln(DebugWriter, v...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Info(v ...interface{}) {
|
func Info(v ...interface{}) {
|
||||||
if InfoWriter != io.Discard {
|
if InfoWriter != io.Discard {
|
||||||
v = append([]interface{}{InfoPrefix}, v...)
|
InfoLog.Print(v...)
|
||||||
fmt.Fprintln(InfoWriter, v...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,35 +70,30 @@ func Print(v ...interface{}) {
|
|||||||
|
|
||||||
func Warn(v ...interface{}) {
|
func Warn(v ...interface{}) {
|
||||||
if WarnWriter != io.Discard {
|
if WarnWriter != io.Discard {
|
||||||
v = append([]interface{}{WarnPrefix}, v...)
|
WarnLog.Print(v...)
|
||||||
fmt.Fprintln(WarnWriter, v...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Error(v ...interface{}) {
|
func Error(v ...interface{}) {
|
||||||
if ErrorWriter != io.Discard {
|
if ErrWriter != io.Discard {
|
||||||
v = append([]interface{}{ErrPrefix}, v...)
|
ErrLog.Print(v...)
|
||||||
fmt.Fprintln(ErrorWriter, v...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fatal(v ...interface{}) {
|
func Fatal(v ...interface{}) {
|
||||||
if ErrorWriter != io.Discard {
|
Error(v...)
|
||||||
v = append([]interface{}{FatalPrefix}, v...)
|
|
||||||
fmt.Fprintln(ErrorWriter, v...)
|
|
||||||
}
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debugf(format string, v ...interface{}) {
|
func Debugf(format string, v ...interface{}) {
|
||||||
if DebugWriter != io.Discard {
|
if DebugWriter != io.Discard {
|
||||||
fmt.Fprintf(DebugWriter, DebugPrefix+" "+format+"\n", v...)
|
DebugLog.Printf(format, v...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Infof(format string, v ...interface{}) {
|
func Infof(format string, v ...interface{}) {
|
||||||
if InfoWriter != io.Discard {
|
if InfoWriter != io.Discard {
|
||||||
fmt.Fprintf(InfoWriter, InfoPrefix+" "+format+"\n", v...)
|
InfoLog.Printf(format, v...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,19 +109,17 @@ func Finfof(w io.Writer, format string, v ...interface{}) {
|
|||||||
|
|
||||||
func Warnf(format string, v ...interface{}) {
|
func Warnf(format string, v ...interface{}) {
|
||||||
if WarnWriter != io.Discard {
|
if WarnWriter != io.Discard {
|
||||||
fmt.Fprintf(WarnWriter, WarnPrefix+" "+format+"\n", v...)
|
WarnLog.Printf(format, v...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Errorf(format string, v ...interface{}) {
|
func Errorf(format string, v ...interface{}) {
|
||||||
if ErrorWriter != io.Discard {
|
if ErrWriter != io.Discard {
|
||||||
fmt.Fprintf(ErrorWriter, ErrPrefix+" "+format+"\n", v...)
|
ErrLog.Printf(format, v...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fatalf(format string, v ...interface{}) {
|
func Fatalf(format string, v ...interface{}) {
|
||||||
if ErrorWriter != io.Discard {
|
Errorf(format, v...)
|
||||||
fmt.Fprintf(ErrorWriter, FatalPrefix+" "+format+"\n", v...)
|
|
||||||
}
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user