-
-
Notifications
You must be signed in to change notification settings - Fork 453
/
log2.go
executable file
·43 lines (34 loc) · 830 Bytes
/
log2.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
package main
import (
"io"
"log"
"os"
)
var (
Info *log.Logger
Warning *log.Logger
Error *log.Logger
)
func LogInit(infoHandle, warningHandle, errorHandle io.Writer) {
Info = log.New(infoHandle,
"INFO: ",
log.Ltime|log.Lshortfile)
Warning = log.New(warningHandle,
"WARNING: ",
log.Ltime|log.Lshortfile)
Error = log.New(errorHandle,
"ERROR: ",
log.Ldate|log.Ltime|log.Lshortfile)
}
func main() {
LogInit(os.Stdout, os.Stderr, os.Stderr)
Info.Println("this is only a info message")
Warning.Println("you can print warnings the same way")
Error.Println("and even errors work as expected")
print("\n")
Info.Printf(`
You can do everything, a normal log.X command can do
In addition you can specify the output stream: stdout or stderr
And define additional prefix und suffix strings.
`)
}