attempt 'capture' mode

This commit is contained in:
Jeff Carr 2024-11-13 21:31:55 -06:00
parent 1bcdcfa2f4
commit 72d75ee478
2 changed files with 28 additions and 4 deletions

View File

@ -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() {

View File

@ -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...))