-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
executable file
·45 lines (39 loc) · 837 Bytes
/
log.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
package main
import (
"fmt"
"io"
"log"
"os"
"path/filepath"
"runtime"
)
func setupLogging() {
//setup our handy loggerino
file, err := openLogFile("./logfile.txt")
if err != nil {
panic(err)
}
wd, err := os.Getwd()
if err != nil {
panic(err)
}
mw := io.MultiWriter(os.Stdout, file)
log.SetOutput(mw)
log.SetFlags(log.Ltime | log.LUTC)
log.Println("Logging started")
// Make a messagebox with the logfile path
fullpath := filepath.Join(wd, file.Name())
fmt.Printf("Logging to file %s\n", fullpath)
}
func openLogFile(path string) (*os.File, error) {
logFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return nil, err
}
return logFile, nil
}
func dumpStackTraces() {
trace := make([]byte, 8192)
length := runtime.Stack(trace, true)
log.Println(string(trace[:length]))
}