-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
48 lines (41 loc) · 860 Bytes
/
logger.go
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
package crawler
import (
"fmt"
"io"
"log"
"os"
"strings"
)
type logger struct {
error_stream io.Writer
output_stream io.Writer
}
var (
DebugLog *log.Logger
)
func init() {
DebugLog = log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime)
}
func (logger *logger) output(format string, a ...any) {
if !strings.HasSuffix(format, "\n") {
format = format + "\n"
}
if logger.output_stream == nil {
fmt.Fprintf(os.Stdout, format, a...)
} else {
fmt.Fprintf(logger.output_stream, format, a...)
}
}
func (logger *logger) error(format string, a ...any) {
if !strings.HasSuffix(format, "\n") {
format = format + "\n"
}
if logger.error_stream == nil {
fmt.Fprintf(os.Stderr, format, a...)
} else {
fmt.Fprintf(logger.error_stream, format, a...)
}
}
func (logger *logger) debug(format string, a ...any) {
DebugLog.Printf(format, a...)
}