From 8e75aff72c3d5add48e70bca86079731a2875cc6 Mon Sep 17 00:00:00 2001 From: nsf Date: Tue, 27 Jan 2015 10:50:39 +0500 Subject: [PATCH] Add a config option to enable the debug mode and redirect logging. --- README.md | 4 ++++ config.go | 14 ++++++++------ server.go | 12 +++++++++++- utils.go | 38 +++++++++++++++++++------------------- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 05059d6c..1bea1099 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,10 @@ You can change all available options using `gocode set` command. The config file A boolean option. If **true**, gocode will try to automatically build out-of-date packages when their source files are modified, in order to obtain the freshest autocomplete results for them. This feature is experimental. Default: **false**. + - *force-debug-output* + + A string option. If is not empty, gocode will forcefully redirect the logging into that file. Also forces enabling of the debug mode on the server side. Default: "" (empty). + ### Debugging If something went wrong, the first thing you may want to do is manually start the gocode daemon with a debug mode enabled and in a separate terminal window. It will show you all the stack traces, panics if any and additional info about autocompletion requests. Shutdown the daemon if it was already started and run a new one explicitly with a debug mode enabled: diff --git a/config.go b/config.go index dd2caa0f..91a7dfae 100644 --- a/config.go +++ b/config.go @@ -19,15 +19,17 @@ import ( //------------------------------------------------------------------------- type config struct { - ProposeBuiltins bool `json:"propose-builtins"` - LibPath string `json:"lib-path"` - Autobuild bool `json:"autobuild"` + ProposeBuiltins bool `json:"propose-builtins"` + LibPath string `json:"lib-path"` + Autobuild bool `json:"autobuild"` + ForceDebugOutput string `json:"force-debug-output"` } var g_config = config{ - ProposeBuiltins: false, - LibPath: "", - Autobuild: false, + ProposeBuiltins: false, + LibPath: "", + Autobuild: false, + ForceDebugOutput: "", } var g_string_to_bool = map[string]bool{ diff --git a/server.go b/server.go index 0807af0c..dfa2c4de 100644 --- a/server.go +++ b/server.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "fmt" "go/build" "log" @@ -9,11 +10,20 @@ import ( "os" "reflect" "runtime" - "bytes" ) func do_server() int { g_config.read() + if g_config.ForceDebugOutput != "" { + // forcefully enable debugging and redirect logging into the + // specified file + *g_debug = true + f, err := os.Create(g_config.ForceDebugOutput) + if err != nil { + panic(err) + } + log.SetOutput(f) + } addr := *g_addr if *g_sock == "unix" { diff --git a/utils.go b/utils.go index 5c03800a..11738ae6 100644 --- a/utils.go +++ b/utils.go @@ -3,6 +3,7 @@ package main import ( "bytes" "fmt" + "go/build" "io/ioutil" "os" "path/filepath" @@ -10,7 +11,6 @@ import ( "strings" "sync" "unicode/utf8" - "go/build" ) // returns truncated 'data' and amount of bytes skipped (for cursor pos adjustment) @@ -149,30 +149,30 @@ type go_build_context struct { func pack_build_context(ctx *build.Context) go_build_context { return go_build_context{ - GOARCH: ctx.GOARCH, - GOOS: ctx.GOOS, - GOROOT: ctx.GOROOT, - GOPATH: ctx.GOPATH, - CgoEnabled: ctx.CgoEnabled, - UseAllFiles: ctx.UseAllFiles, - Compiler: ctx.Compiler, - BuildTags: ctx.BuildTags, - ReleaseTags: ctx.ReleaseTags, + GOARCH: ctx.GOARCH, + GOOS: ctx.GOOS, + GOROOT: ctx.GOROOT, + GOPATH: ctx.GOPATH, + CgoEnabled: ctx.CgoEnabled, + UseAllFiles: ctx.UseAllFiles, + Compiler: ctx.Compiler, + BuildTags: ctx.BuildTags, + ReleaseTags: ctx.ReleaseTags, InstallSuffix: ctx.InstallSuffix, } } func unpack_build_context(ctx *go_build_context) build.Context { return build.Context{ - GOARCH: ctx.GOARCH, - GOOS: ctx.GOOS, - GOROOT: ctx.GOROOT, - GOPATH: ctx.GOPATH, - CgoEnabled: ctx.CgoEnabled, - UseAllFiles: ctx.UseAllFiles, - Compiler: ctx.Compiler, - BuildTags: ctx.BuildTags, - ReleaseTags: ctx.ReleaseTags, + GOARCH: ctx.GOARCH, + GOOS: ctx.GOOS, + GOROOT: ctx.GOROOT, + GOPATH: ctx.GOPATH, + CgoEnabled: ctx.CgoEnabled, + UseAllFiles: ctx.UseAllFiles, + Compiler: ctx.Compiler, + BuildTags: ctx.BuildTags, + ReleaseTags: ctx.ReleaseTags, InstallSuffix: ctx.InstallSuffix, } }