don't use STDERR anymore. also timestamps off by default
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
e1d7a5c2cc
commit
1631c72f70
Notes:
Jeff Carr
2025-01-09 21:22:10 -06:00
// `autogen:go.mod` module go.wit.com/log go 1.20 // `autogen:`
1
flags.go
1
flags.go
|
@ -56,6 +56,7 @@ type LogFlag struct {
|
||||||
|
|
||||||
var flags []*LogFlag
|
var flags []*LogFlag
|
||||||
var daemonMode bool
|
var daemonMode bool
|
||||||
|
var timestamps bool = false
|
||||||
var httpMode http.ResponseWriter
|
var httpMode http.ResponseWriter
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
29
reallog.go
29
reallog.go
|
@ -15,6 +15,11 @@ func DaemonMode(b bool) {
|
||||||
daemonMode = b
|
daemonMode = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Timestamps(b bool) {
|
||||||
|
timestamps = b
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var captureMode io.Writer
|
var captureMode io.Writer
|
||||||
|
|
||||||
func CaptureMode(w io.Writer) {
|
func CaptureMode(w io.Writer) {
|
||||||
|
@ -59,15 +64,22 @@ func realPrintln(a ...any) {
|
||||||
} else {
|
} else {
|
||||||
// put timestamps on each line
|
// put timestamps on each line
|
||||||
if captureMode == nil {
|
if captureMode == nil {
|
||||||
|
if timestamps {
|
||||||
reallog.Println(a...)
|
reallog.Println(a...)
|
||||||
|
} else {
|
||||||
|
fmt.Println(a...)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: add datestamp
|
// TODO: add datestamp
|
||||||
fmt.Fprintln(captureMode, a...)
|
fmt.Fprintln(captureMode, a...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if httpMode != nil {
|
if httpMode != nil {
|
||||||
now := time.Now()
|
var timestamp string
|
||||||
timestamp := now.Format("2006/01/02 15:04:05") // bummer. other date doesn't work?
|
if timestamps {
|
||||||
|
now := time.Now()
|
||||||
|
timestamp = now.Format("2006/01/02 15:04:05") // todo: fix GO so Nov 5 1955 works here
|
||||||
|
}
|
||||||
s := timestamp + " " + fmt.Sprint(a...)
|
s := timestamp + " " + fmt.Sprint(a...)
|
||||||
fmt.Fprintln(httpMode, s)
|
fmt.Fprintln(httpMode, s)
|
||||||
if flusher != nil {
|
if flusher != nil {
|
||||||
|
@ -87,14 +99,21 @@ func realPrintf(s string, a ...any) {
|
||||||
} else {
|
} else {
|
||||||
// put timestamps on each line
|
// put timestamps on each line
|
||||||
if captureMode == nil {
|
if captureMode == nil {
|
||||||
reallog.Printf(s, a...)
|
if timestamps {
|
||||||
|
reallog.Printf(s, a...)
|
||||||
|
} else {
|
||||||
|
fmt.Printf(s, a...)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(captureMode, s, a...)
|
fmt.Fprintf(captureMode, s, a...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if httpMode != nil {
|
if httpMode != nil {
|
||||||
now := time.Now()
|
var timestamp string
|
||||||
timestamp := now.Format("2006/01/02 15:04:05") // bummer. other date doesn't work?
|
if timestamps {
|
||||||
|
now := time.Now()
|
||||||
|
timestamp = now.Format("2006/01/02 15:04:05")
|
||||||
|
}
|
||||||
s := timestamp + " " + fmt.Sprintf(s, a...)
|
s := timestamp + " " + fmt.Sprintf(s, a...)
|
||||||
fmt.Fprintln(httpMode, s)
|
fmt.Fprintln(httpMode, s)
|
||||||
if flusher != nil {
|
if flusher != nil {
|
||||||
|
|
Loading…
Reference in New Issue