73 lines
1.1 KiB
Go
73 lines
1.1 KiB
Go
package log
|
|
|
|
// implements 'daemon' mode so switches to fmt
|
|
// instead of log so that timestamps are not printed twice
|
|
|
|
import (
|
|
"fmt"
|
|
reallog "log"
|
|
"net/http"
|
|
)
|
|
|
|
func DaemonMode(b bool) {
|
|
daemonMode = b
|
|
}
|
|
|
|
func HttpMode(w http.ResponseWriter) {
|
|
httpMode = w
|
|
}
|
|
|
|
func DaemonShow() {
|
|
if daemonMode {
|
|
fmt.Println("daemonMode=true")
|
|
} else {
|
|
fmt.Println("daemonMode=false")
|
|
}
|
|
}
|
|
|
|
func realPrintln(a ...any) {
|
|
if daemonMode {
|
|
fmt.Println(a...)
|
|
} else {
|
|
reallog.Println(a...)
|
|
}
|
|
if httpMode != nil {
|
|
fmt.Fprintln(httpMode, fmt.Sprint(a...))
|
|
}
|
|
}
|
|
|
|
func realPrintf(s string, a ...any) {
|
|
if daemonMode {
|
|
fmt.Printf(s, a...)
|
|
} else {
|
|
reallog.Printf(s, a...)
|
|
}
|
|
if httpMode != nil {
|
|
fmt.Fprintln(httpMode, fmt.Sprintf(s, a...))
|
|
}
|
|
}
|
|
|
|
func realSprint(a ...any) string {
|
|
return fmt.Sprint(a...)
|
|
}
|
|
|
|
func realSprintf(s string, a ...any) string {
|
|
return fmt.Sprintf(s, a...)
|
|
}
|
|
|
|
func realSprintln(a ...any) string {
|
|
return fmt.Sprintln(a...)
|
|
}
|
|
|
|
func realFatalln(a ...any) {
|
|
reallog.Fatalln(a...)
|
|
}
|
|
|
|
func realFatalf(s string, a ...any) {
|
|
reallog.Fatalf(s, a...)
|
|
}
|
|
|
|
func realFatal(s string, a ...any) {
|
|
reallog.Fatalf(s, a...)
|
|
}
|