-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
64 lines (51 loc) · 1.53 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"io"
"log"
"os"
)
func main() {
log.SetFlags(log.Ldate)
log.Println("Using log.Ldate")
// the time in the local time zone: 01:23:23
log.SetFlags(log.Ltime)
log.Println("Using log.Ltime")
// microsecond resolution: 01:23:23.123123
log.SetFlags(log.Lmicroseconds)
log.Println("Using log.Lmicroseconds")
// full file name and line number: /a/b/c/d.go:23
log.SetFlags(log.Llongfile)
log.Println("Using log.Llongfile")
// final file name element and line number: d.go:23
log.SetFlags(log.Lshortfile)
log.Println("Using log.Lshortfile")
// if Ldate or Ltime is set, use UTC rather than the local time zone
log.SetFlags(log.Ldate | log.Ltime | log.LUTC)
log.Println("Using log.LUTC")
// initial values for the standard logger
log.SetFlags(log.LstdFlags)
log.Println("Using log.LstdFlags")
// set prefix
log.SetPrefix("INFO ")
log.Println("Using a prefix at beginning of line")
// set prefix
log.SetPrefix("INFO ")
log.SetFlags(log.Lmsgprefix | log.LstdFlags)
log.Println("Using a prefix before actual message")
// log to file only. If it exists will append
f, err := os.OpenFile("app.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()
log.SetOutput(f)
log.Println("hello, world (file)")
log.Println("hello, world (file)")
log.Println("hello, world (file)")
// log to a file and standard out
w := io.MultiWriter(os.Stdout, f)
log.SetOutput(w)
log.Println("hello, world (both)")
log.Println("hello, world (both)")
log.Println("hello, world (both)")
}