Skip to content

Commit

Permalink
update logger
Browse files Browse the repository at this point in the history
Closes #235
  • Loading branch information
mattn committed Mar 18, 2024
1 parent 1802a88 commit d1e5344
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions langserver/handle_workspace_did_change_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package langserver
import (
"context"
"encoding/json"
"log"
"os"
"time"

"github.com/sourcegraph/jsonrpc2"
Expand Down Expand Up @@ -44,5 +46,21 @@ func (h *langHandler) didChangeConfiguration(config *Config) (any, error) {
h.formatDebounce = time.Duration(config.FormatDebounce)
}

if config.LogFile != "" {
f, err := os.OpenFile(config.LogFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0o660)
if err == nil {
if h.logger != nil {
if w, ok := h.logger.Writer().(*os.File); ok {
w.Close()
}
}
h.logger = log.New(f, "", log.LstdFlags)
}
}

if config.LogLevel > 0 {
h.loglevel = config.LogLevel
}

return nil, nil
}

0 comments on commit d1e5344

Please sign in to comment.