diff options
| author | Jeff Carr <[email protected]> | 2024-11-13 21:31:55 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-13 21:31:55 -0600 |
| commit | 72d75ee4786d3b0379b45dbbbddf3b80393005d7 (patch) | |
| tree | dc553f8fb20466e2176b081d2d6f96cfddc8d449 | |
| parent | 1bcdcfa2f46c550e1d02bc859b80a31fac8792e7 (diff) | |
attempt 'capture' mode
| -rw-r--r-- | flags.go | 2 | ||||
| -rw-r--r-- | reallog.go | 30 |
2 files changed, 28 insertions, 4 deletions
@@ -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() { @@ -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 { - fmt.Println(a...) + if captureMode == nil { + fmt.Println(a...) + } else { + fmt.Fprintln(captureMode, a...) + } } else { - reallog.Println(a...) + 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 { - fmt.Printf(s, a...) + if captureMode == nil { + fmt.Printf(s, a...) + } else { + fmt.Fprintf(captureMode, s, a...) + } } else { - reallog.Printf(s, a...) + if captureMode == nil { + reallog.Printf(s, a...) + } else { + fmt.Fprintf(captureMode, s, a...) + } } if httpMode != nil { fmt.Fprintln(httpMode, fmt.Sprintf(s, a...)) |
