attempt 'capture' mode
This commit is contained in:
parent
1bcdcfa2f4
commit
72d75ee478
2
flags.go
2
flags.go
|
@ -27,6 +27,7 @@ package log
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
@ -56,6 +57,7 @@ type LogFlag struct {
|
|||
|
||||
var flags []*LogFlag
|
||||
var daemonMode bool
|
||||
var captureMode *os.File
|
||||
var httpMode http.ResponseWriter
|
||||
|
||||
func init() {
|
||||
|
|
24
reallog.go
24
reallog.go
|
@ -7,12 +7,17 @@ import (
|
|||
"fmt"
|
||||
reallog "log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func DaemonMode(b bool) {
|
||||
daemonMode = b
|
||||
}
|
||||
|
||||
func CaptureMode(f *os.File) {
|
||||
captureMode = f
|
||||
}
|
||||
|
||||
func HttpMode(w http.ResponseWriter) {
|
||||
httpMode = w
|
||||
}
|
||||
|
@ -27,9 +32,18 @@ func DaemonShow() {
|
|||
|
||||
func realPrintln(a ...any) {
|
||||
if daemonMode {
|
||||
if captureMode == nil {
|
||||
fmt.Println(a...)
|
||||
} else {
|
||||
reallog.Println(a...)
|
||||
fmt.Fprintln(captureMode, a...)
|
||||
}
|
||||
} else {
|
||||
if captureMode == nil {
|
||||
fmt.Println(a...)
|
||||
} else {
|
||||
// TODO: add datestamp
|
||||
fmt.Fprintln(captureMode, a...)
|
||||
}
|
||||
}
|
||||
if httpMode != nil {
|
||||
s := fmt.Sprint(a...)
|
||||
|
@ -39,9 +53,17 @@ func realPrintln(a ...any) {
|
|||
|
||||
func realPrintf(s string, a ...any) {
|
||||
if daemonMode {
|
||||
if captureMode == nil {
|
||||
fmt.Printf(s, a...)
|
||||
} else {
|
||||
fmt.Fprintf(captureMode, s, a...)
|
||||
}
|
||||
} else {
|
||||
if captureMode == nil {
|
||||
reallog.Printf(s, a...)
|
||||
} else {
|
||||
fmt.Fprintf(captureMode, s, a...)
|
||||
}
|
||||
}
|
||||
if httpMode != nil {
|
||||
fmt.Fprintln(httpMode, fmt.Sprintf(s, a...))
|
||||
|
|
Loading…
Reference in New Issue