forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example1.go
52 lines (40 loc) · 1.31 KB
/
example1.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
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// http://play.golang.org/p/xO5OuPOJef
// Sample program to show how to use the log package
// from the standard library.
package main
import (
"log"
"os"
)
// init is called before main.
func init() {
// Change the output device from the default
// stderr to stdout.
log.SetOutput(os.Stdout)
// Set the prefix string for each log line.
log.SetPrefix("TRACE: ")
// Set the extra log info.
setFlags()
}
// setFlags adds extra information on each log line.
func setFlags() {
/*
Ldate // the date: 2009/01/23
Ltime // the time: 01:23:23
Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime.
Llongfile // full file name and line number: /a/b/c/d.go:23
Lshortfile // final file name element and line number: d.go:23. overrides Llongfile
LstdFlags // Ldate | Ltime // initial values for the standard logger
*/
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
// main is the entry point for the application.
func main() {
log.Println("main function started")
names := []string{"Henry", "Lisa", "Bill", "Matt"}
log.Printf("These are named %+v\n", names)
log.Fatalln("Terminate Program")
log.Println("main function ended")
}