summaryrefslogtreecommitdiff
path: root/reallog.go
blob: 347db8573a55e1b00a6f77ca5ed49dd8f235909c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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 {
		s := fmt.Sprint(a...)
		fmt.Fprintln(httpMode, s)
	}
}

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