1
0
mirror of https://github.com/golang/go synced 2024-09-30 14:18:32 -06:00

cmd/golsp: enable logging to a default location

Add a default "auto" value to the "--logfile" flag that allows logs to be
written to a default location.

Change-Id: I1952ad2622b824795906c6b8183b58f88c35fb62
Reviewed-on: https://go-review.googlesource.com/c/153197
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2018-12-07 11:33:44 -05:00
parent e00c0697c2
commit 85346a3911

View File

@ -16,6 +16,7 @@ import (
"io"
"log"
"os"
"path/filepath"
"runtime"
"runtime/pprof"
"runtime/trace"
@ -29,10 +30,10 @@ var (
cpuprofile = flag.String("cpuprofile", "", "write CPU profile to this file")
memprofile = flag.String("memprofile", "", "write memory profile to this file")
traceFlag = flag.String("trace", "", "write trace log to this file")
logfile = flag.String("logfile", "", "filename to log to. if value is \"auto\", then logging to a default output file is enabled")
// Flags for compatitibility with VSCode.
logfile = flag.String("logfile", "", "filename to log to")
mode = flag.String("mode", "", "no effect")
mode = flag.String("mode", "", "no effect")
)
func main() {
@ -90,7 +91,11 @@ func main() {
out := os.Stderr
if *logfile != "" {
f, err := os.Create(*logfile)
filename := *logfile
if filename == "auto" {
filename = filepath.Join(os.TempDir(), fmt.Sprintf("golsp-%d.log", os.Getpid()))
}
f, err := os.Create(filename)
if err != nil {
log.Fatalf("Unable to create log file: %v", err)
}