Merge pull request #21 from tobyxdd/wip-log-level

Add log level & format environment variables
This commit is contained in:
Toby 2020-07-07 18:39:11 -07:00 committed by GitHub
commit c0ce9c8ab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -154,3 +154,11 @@ To prevent firewalls from potentially detecting & blocking the protocol, a simpl
| Max receive window size per connection | recv_window_conn | -recv-window-conn |
| Max receive window size | recv_window | -recv-window |
| Obfuscation key | obfs | -obfs |
## Logs
By default, the program outputs DEBUG level, text format logs via stdout.
To change the logging level, set `LOGGING_LEVEL` environment variable, which supports `panic`, `fatal`, `error`, `warn`, `info`, ` debug`, `trace`
To print JSON instead, set `LOGGING_FORMATTER` to `json`

View File

@ -152,3 +152,11 @@ shady_hacker smokeweed420
| 单连接最大接收窗口大小 | recv_window_conn | -recv-window-conn |
| 总最大接收窗口大小 | recv_window | -recv-window |
| 混淆密钥 | obfs | -obfs |
## 日志
程序默认在 stdout 输出 DEBUG 级别,文字格式的日志。
如果需要修改日志级别可以使用 `LOGGING_LEVEL` 环境变量,支持 `panic`, `fatal`, `error`, `warn`, `info`, `debug`, `trace`
如果需要输出 JSON 可以把 `LOGGING_FORMATTER` 设置为 `json`

View File

@ -23,10 +23,22 @@ var modeMap = map[string]func(args []string){
func init() {
logrus.SetOutput(os.Stdout)
logrus.SetLevel(logrus.DebugLevel)
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
})
lvl, err := logrus.ParseLevel(os.Getenv("LOGGING_LEVEL"))
if err == nil {
logrus.SetLevel(lvl)
} else {
logrus.SetLevel(logrus.DebugLevel)
}
fmtter := os.Getenv("LOGGING_FORMATTER")
if strings.ToLower(fmtter) == "json" {
logrus.SetFormatter(&logrus.JSONFormatter{})
} else {
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
})
}
}
func main() {