提交 c944ccd0 编写于 作者: martianzhang's avatar martianzhang

fix mac os stdout print buffer truncate

  When set log to console, if fmt.Print larger than 1K
  the output buffer will be truncate. This problem will be
  trigger when set log to stdout, beego and soar both print their
  output into stdout, and this may come into confusing status in
  mac os.

  For fixing this problem, we only allow set log to file not.
  SOAR never write SQL suggest into log. Only developer should be
  concern about log, common user have no need of looking up log.
上级 3dda683a
......@@ -131,14 +131,6 @@ type Configuration struct {
MaxPrettySQLLength int `yaml:"max-pretty-sql-length"` // 超出该长度的SQL会转换成指纹输出
}
// getDefaultLogOutput get default log-output by runtime.GOOS
func getDefaultLogOutput() string {
if runtime.GOOS == "windows" {
return "nul"
}
return os.Stderr.Name()
}
// Config 默认设置
var Config = &Configuration{
OnlineDSN: &dsn{
......@@ -178,7 +170,7 @@ var Config = &Configuration{
SpaghettiQueryLength: 2048,
AllowDropIndex: false,
LogLevel: 3,
LogOutput: getDefaultLogOutput(),
LogOutput: "soar.log",
ReportType: "markdown",
ReportCSS: "",
ReportJavascript: "",
......
......@@ -19,7 +19,6 @@ package common
import (
"flag"
"os"
"runtime"
"testing"
"github.com/kr/pretty"
......@@ -27,17 +26,6 @@ import (
var update = flag.Bool("update", false, "update .golden files")
func TestGetDefaultLogOutput(t *testing.T) {
output := getDefaultLogOutput()
if runtime.GOOS == "windows" && output != "nul" {
t.Error("windows default -log-output not nul")
}
if runtime.GOOS != "windows" && output != "/dev/stderr" {
t.Error("default -log-output not /dev/stderr")
}
}
func TestParseConfig(t *testing.T) {
err := ParseConfig("")
if err != nil {
......
......@@ -39,17 +39,10 @@ func init() {
// LoggerInit Log配置初始化
func LoggerInit() {
Log.SetLevel(Config.LogLevel)
if Config.LogOutput == logs.AdapterConsole {
err := Log.SetLogger(logs.AdapterConsole)
if err != nil {
fmt.Println(err.Error())
}
} else {
func() { _ = Log.DelLogger(logs.AdapterFile) }()
err := Log.SetLogger(logs.AdapterFile, fmt.Sprintf(`{"filename":"%s","level":7,"maxlines":0,"maxsize":0,"daily":false,"maxdays":0}`, Config.LogOutput))
if err != nil {
fmt.Println(err.Error())
}
func() { _ = Log.DelLogger(logs.AdapterFile) }()
err := Log.SetLogger(logs.AdapterFile, fmt.Sprintf(`{"filename":"%s","level":7,"maxlines":0,"maxsize":0,"daily":false,"maxdays":0}`, Config.LogOutput))
if err != nil {
fmt.Println(err.Error())
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册