mirror of
https://github.com/golang/go
synced 2024-11-18 11:04:42 -07: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:
parent
e00c0697c2
commit
85346a3911
@ -16,6 +16,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"runtime/trace"
|
"runtime/trace"
|
||||||
@ -29,10 +30,10 @@ var (
|
|||||||
cpuprofile = flag.String("cpuprofile", "", "write CPU profile to this file")
|
cpuprofile = flag.String("cpuprofile", "", "write CPU profile to this file")
|
||||||
memprofile = flag.String("memprofile", "", "write memory profile to this file")
|
memprofile = flag.String("memprofile", "", "write memory profile to this file")
|
||||||
traceFlag = flag.String("trace", "", "write trace log 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.
|
// 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() {
|
func main() {
|
||||||
@ -90,7 +91,11 @@ func main() {
|
|||||||
|
|
||||||
out := os.Stderr
|
out := os.Stderr
|
||||||
if *logfile != "" {
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("Unable to create log file: %v", err)
|
log.Fatalf("Unable to create log file: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user