Browse Source
Merge pull request #192 from tinattwang/main
optimize the output config of log
pull/193/head
yedf2
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
5 additions and
5 deletions
-
conf.sample.yml
-
dtmcli/logger/log.go
-
dtmcli/logger/logger_test.go
|
|
|
@ -50,7 +50,7 @@ |
|
|
|
|
|
|
|
# LogLevel: 'info' # default: info. can be debug|info|warn|error |
|
|
|
# Log: |
|
|
|
# Outputs: 'stderr' # default: stderr, split by |, you can append files to Outputs if need. example:'stderr|/tmp/test.log' |
|
|
|
# Outputs: 'stderr' # default: stderr, split by ",", you can append files to Outputs if need. example:'stderr,/tmp/test.log' |
|
|
|
# RotationEnable: 0 # default: 0 |
|
|
|
# RotationConfigJson: '{}' # example: '{"maxsize": 100, "maxage": 0, "maxbackups": 0, "localtime": false, "compress": false}' |
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +49,7 @@ func InitLog(level string) { |
|
|
|
|
|
|
|
// InitLog2 specify advanced log config
|
|
|
|
func InitLog2(level string, outputs string, logRotationEnable int64, logRotateConfigJSON string) { |
|
|
|
outputPaths := strings.Split(outputs, "|") |
|
|
|
outputPaths := strings.Split(outputs, ",") |
|
|
|
for i, v := range outputPaths { |
|
|
|
if logRotationEnable != 0 && v != StdErr && v != StdOut { |
|
|
|
outputPaths[i] = fmt.Sprintf("lumberjack://%s", v) |
|
|
|
|
|
|
|
@ -17,12 +17,12 @@ func TestInitLog(t *testing.T) { |
|
|
|
FatalfIf(false, "nothing") |
|
|
|
FatalIfError(nil) |
|
|
|
|
|
|
|
InitLog2("debug", "test.log|stderr", 0, "") |
|
|
|
InitLog2("debug", "test.log,stderr", 0, "") |
|
|
|
Debugf("a debug msg to console and file") |
|
|
|
|
|
|
|
InitLog2("debug", "test2.log|/tmp/dtm-test1.log|/tmp/dtm-test.log|stdout|stderr", 1, |
|
|
|
InitLog2("debug", "test2.log,/tmp/dtm-test1.log,/tmp/dtm-test.log,stdout,stderr", 1, |
|
|
|
"{\"maxsize\": 1, \"maxage\": 1, \"maxbackups\": 1, \"compress\": false}") |
|
|
|
Debugf("a debug msg to /tmp/dtm-test.log|test2.log|stdout|stderr") |
|
|
|
Debugf("a debug msg to /tmp/dtm-test.log and test2.log and stdout and stderr") |
|
|
|
|
|
|
|
// _ = os.Remove("test.log")
|
|
|
|
} |
|
|
|
|