forked from GoesToEleven/GolangTraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
31 lines (26 loc) · 720 Bytes
/
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
package main
import (
"fmt"
"log"
"os"
)
func init() {
nf, err := os.Create("log.txt")
if err != nil {
fmt.Println(err)
}
log.SetOutput(nf)
}
func main() {
_, err := os.Open("no-file.txt")
if err != nil {
// fmt.Println("err happened", err)
log.Println("err happened", err)
// log.Fatalln(err)
// panic(err)
}
}
/*
Package log implements a simple logging package ... writes to standard error and prints the date and time of each logged message ... the Fatal functions call os.Exit(1) after writing the log message ... the Panic functions call panic after writing the log message.
*/
// Println calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println.