Skip to content

Commit

Permalink
feat: windows compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Jun 22, 2021
1 parent 3a232bb commit d947510
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion api/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,6 @@ func printInfo() {
fmt.Fprintf(os.Stdout, "%-8s: %s:%d\n", "HTTPS Listen", conf.SSLHost, conf.SSLPort)
}
fmt.Fprintf(os.Stdout, "%-8s: %s\n", "Loglevel", conf.ErrorLogLevel)
fmt.Fprintf(os.Stdout, "%-8s: %s\n\n", "Logfile", conf.ErrorLogPath)
fmt.Fprintf(os.Stdout, "%-8s: %s\n", "ErrorLogFile", conf.ErrorLogPath)
fmt.Fprintf(os.Stdout, "%-8s: %s\n\n", "AccessLogFile", conf.AccessLogPath)
}
2 changes: 2 additions & 0 deletions api/conf/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ conf:
file_path:
logs/error.log # supports relative path, absolute path, standard output
# such as: logs/error.log, /tmp/logs/error.log, /dev/stdout, /dev/stderr
# such as absolute path on Windows: winfile:///C:\error.log
access_log:
file_path:
logs/access.log # supports relative path, absolute path, standard output
# such as: logs/access.log, /tmp/logs/access.log, /dev/stdout, /dev/stderr
# such as absolute path on Windows: winfile:///C:\access.log
# log example: 2020-12-09T16:38:09.039+0800 INFO filter/logging.go:46 /apisix/admin/routes/r1 {"status": 401, "host": "127.0.0.1:9000", "query": "asdfsafd=adf&a=a", "requestId": "3d50ecb8-758c-46d1-af5b-cd9d1c820156", "latency": 0, "remoteIP": "127.0.0.1", "method": "PUT", "errs": []}
max_cpu: 0 # supports tweaking with the number of OS threads are going to be used for parallelism. Default value: 0 [will use max number of available cpu cores considering hyperthreading (if any)]. If the value is negative, is will not touch the existing parallelism profile.

Expand Down
30 changes: 19 additions & 11 deletions api/internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"

"github.com/tidwall/gjson"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -191,28 +192,35 @@ func setConf() {
if config.Conf.Log.ErrorLog.FilePath != "" {
ErrorLogPath = config.Conf.Log.ErrorLog.FilePath
}

// access log
if config.Conf.Log.AccessLog.FilePath != "" {
AccessLogPath = config.Conf.Log.AccessLog.FilePath
}

if !filepath.IsAbs(ErrorLogPath) {
if strings.HasPrefix(ErrorLogPath, "winfile") {
return
}
ErrorLogPath, err = filepath.Abs(filepath.Join(WorkDir, ErrorLogPath))
if err != nil {
panic(err)
}
}

// access log
if config.Conf.Log.AccessLog.FilePath != "" {
AccessLogPath = config.Conf.Log.AccessLog.FilePath
if runtime.GOOS == "windows" {
ErrorLogPath = `winfile:///` + ErrorLogPath
}
}
if !filepath.IsAbs(AccessLogPath) {
if strings.HasPrefix(AccessLogPath, "winfile") {
return
}
AccessLogPath, err = filepath.Abs(filepath.Join(WorkDir, AccessLogPath))
if err != nil {
panic(err)
}
}

// compatible with Windows
if runtime.GOOS == "windows" {
ErrorLogPath = `winfile:///` + ErrorLogPath
AccessLogPath = `winfile:///` + AccessLogPath
if runtime.GOOS == "windows" {
AccessLogPath = `winfile:///` + AccessLogPath
}
}

AllowList = config.Conf.AllowList
Expand Down

0 comments on commit d947510

Please sign in to comment.