iotex-core
iotex-core copied to clipboard
[pkg] rotate log file
Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes https://github.com/iotexproject/iotex-core/issues/2661
Type of change
Please delete options that are not relevant.
- [] Bug fix (non-breaking change which fixes an issue)
- [] New feature (non-breaking change which adds functionality)
- [] Code refactor or improvement
- [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
- [] This change requires a documentation update
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- [] make test
- [] fullsync
- [] Other test (please specify)
Test Configuration:
- Firmware version:
- Hardware:
- Toolchain:
- SDK:
Checklist:
- [] My code follows the style guidelines of this project
- [] I have performed a self-review of my code
- [] I have commented my code, particularly in hard-to-understand areas
- [] I have made corresponding changes to the documentation
- [] My changes generate no new warnings
- [] I have added tests that prove my fix is effective or that my feature works
- [] New and existing unit tests pass locally with my changes
- [] Any dependent changes have been merged and published in downstream modules
Codecov Report
Merging #3638 (a0fef85) into master (e9732a1) will decrease coverage by
0.32%
. The diff coverage is77.90%
.
@@ Coverage Diff @@
## master #3638 +/- ##
==========================================
- Coverage 74.95% 74.62% -0.33%
==========================================
Files 269 264 -5
Lines 23819 23687 -132
==========================================
- Hits 17854 17677 -177
- Misses 5039 5083 +44
- Partials 926 927 +1
Impacted Files | Coverage Δ | |
---|---|---|
db/trie/mptrie/node.go | 100.00% <ø> (ø) |
|
ioctl/newcmd/action/action.go | 79.62% <ø> (+0.09%) |
:arrow_up: |
ioctl/newcmd/node/nodedelegate.go | 70.19% <0.00%> (-0.95%) |
:arrow_down: |
ioctl/newcmd/node/nodeprobationlist.go | 90.90% <0.00%> (-4.33%) |
:arrow_down: |
action/protocol/execution/evm/evm.go | 44.57% <26.66%> (-0.86%) |
:arrow_down: |
db/trie/mptrie/hashnode.go | 36.36% <41.17%> (-54.55%) |
:arrow_down: |
db/trie/mptrie/merklepatriciatrie.go | 78.73% <46.80%> (-12.70%) |
:arrow_down: |
db/trie/mptrie/leafiterator.go | 62.06% <50.00%> (ø) |
|
action/protocol/execution/evm/evmstatedbadapter.go | 65.87% <64.28%> (-0.04%) |
:arrow_down: |
db/trie/mptrie/extensionnode.go | 89.89% <94.28%> (-3.09%) |
:arrow_down: |
... and 14 more |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
After reach MaxSize
MB, s.log will be rotated auto. After MaxAge
days it will be removed auto.
The rotated log's name has the created time like : /var/log/s-2022-09-14T19-27-26.648.log
pls fix the log rotate issue with logrotate
From 53f7cfeb60fca7590b3a2660007c606dc2783bea Mon Sep 17 00:00:00 2001 From: huof6890 [email protected] Date: Wed, 14 Sep 2022 20:05:38 +0800 Subject: [PATCH] add lumberjack
config/standalone-config.yaml | 7 ++++++- go.mod | 1 + go.sum | 2 ++ pkg/log/log.go | 13 ++++++++----- 4 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/config/standalone-config.yaml b/config/standalone-config.yaml index 3db556854e..1be8022d94 100644 --- a/config/standalone-config.yaml +++ b/config/standalone-config.yaml @@ -15,4 +15,9 @@ log: outputPaths: ["stderr", "stdout"] errorOutputPaths: ["stderr"] stderrRedirectFile: /var/log/s.log
- stdLogRedirect: true \ No newline at end of file
-
stdLogRedirect: true
-
lumberjack:
-
maxsize: 10
-
maxage: 30
-
maxbackups: 100
-
localtime: true \ No newline at end of file diff --git a/go.mod b/go.mod index f249692541..95660caa22 100644 --- a/go.mod +++ b/go.mod @@ -196,6 +196,7 @@ require ( golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect google.golang.org/appengine v1.6.5 // indirect
-
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/square/go-jose.v2 v2.5.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index dc8724f64d..d7629fb532 100644 --- a/go.sum +++ b/go.sum @@ -1707,6 +1707,8 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= diff --git a/pkg/log/log.go b/pkg/log/log.go index 7b903f642c..91206868fa 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -15,16 +15,18 @@ import ( "go.elastic.co/ecszap" "go.uber.org/zap" "go.uber.org/zap/zapcore"
-
"gopkg.in/natefinch/lumberjack.v2"
"github.com/pkg/errors" )
// GlobalConfig defines the global logger configurations. type GlobalConfig struct {
- Zap *zap.Config
json:"zap" yaml:"zap"
- StderrRedirectFile *string
json:"stderrRedirectFile" yaml:"stderrRedirectFile"
- RedirectStdLog bool
json:"stdLogRedirect" yaml:"stdLogRedirect"
- EcsIntegration bool
json:"ecsIntegration" yaml:"ecsIntegration"
- Zap *zap.Config
json:"zap" yaml:"zap"
- Lumberjack *lumberjack.Logger
json:"lumberjack" yaml:"lumberjack"
- StderrRedirectFile *string
json:"stderrRedirectFile" yaml:"stderrRedirectFile"
- RedirectStdLog bool
json:"stdLogRedirect" yaml:"stdLogRedirect"
- EcsIntegration bool
json:"ecsIntegration" yaml:"ecsIntegration"
}
var ( @@ -92,10 +94,11 @@ func InitLoggers(globalCfg GlobalConfig, subCfgs map[string]GlobalConfig, opts . if err != nil { return err }
-
cfg.Lumberjack.Filename = stderrF.Name() cores = append(cores, zapcore.NewCore( zapcore.NewJSONEncoder(cfg.Zap.EncoderConfig),
-
zapcore.AddSync(stderrF),
-
zapcore.AddSync(cfg.Lumberjack), cfg.Zap.Level)) }
diff --git a/config/standalone-config.yaml b/config/standalone-config.yaml index 3db556854e..1be8022d94 100644 --- a/config/standalone-config.yaml +++ b/config/standalone-config.yaml @@ -15,4 +15,9 @@ log: outputPaths: ["stderr", "stdout"] errorOutputPaths: ["stderr"] stderrRedirectFile: /var/log/s.log
- stdLogRedirect: true \ No newline at end of file
-
stdLogRedirect: true
-
lumberjack:
-
maxsize: 10
-
maxage: 30
-
maxbackups: 100
-
localtime: true \ No newline at end of file diff --git a/go.mod b/go.mod index f249692541..95660caa22 100644 --- a/go.mod +++ b/go.mod @@ -196,6 +196,7 @@ require ( golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect google.golang.org/appengine v1.6.5 // indirect
-
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/square/go-jose.v2 v2.5.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index dc8724f64d..d7629fb532 100644 --- a/go.sum +++ b/go.sum @@ -1707,6 +1707,8 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= diff --git a/pkg/log/log.go b/pkg/log/log.go index 7b903f642c..91206868fa 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -15,16 +15,18 @@ import ( "go.elastic.co/ecszap" "go.uber.org/zap" "go.uber.org/zap/zapcore"
-
"gopkg.in/natefinch/lumberjack.v2"
"github.com/pkg/errors" )
// GlobalConfig defines the global logger configurations. type GlobalConfig struct {
- Zap *zap.Config
json:"zap" yaml:"zap"
- StderrRedirectFile *string
json:"stderrRedirectFile" yaml:"stderrRedirectFile"
- RedirectStdLog bool
json:"stdLogRedirect" yaml:"stdLogRedirect"
- EcsIntegration bool
json:"ecsIntegration" yaml:"ecsIntegration"
- Zap *zap.Config
json:"zap" yaml:"zap"
- Lumberjack *lumberjack.Logger
json:"lumberjack" yaml:"lumberjack"
- StderrRedirectFile *string
json:"stderrRedirectFile" yaml:"stderrRedirectFile"
- RedirectStdLog bool
json:"stdLogRedirect" yaml:"stdLogRedirect"
- EcsIntegration bool
json:"ecsIntegration" yaml:"ecsIntegration"
}
var ( @@ -92,10 +94,11 @@ func InitLoggers(globalCfg GlobalConfig, subCfgs map[string]GlobalConfig, opts . if err != nil { return err }
-
cfg.Lumberjack.Filename = stderrF.Name() cores = append(cores, zapcore.NewCore( zapcore.NewJSONEncoder(cfg.Zap.EncoderConfig),
-
zapcore.AddSync(stderrF),
-
zapcore.AddSync(cfg.Lumberjack), cfg.Zap.Level)) }
crond
service in container cannot autorun after docker run
, logrotate
depends on crond
and cannot effect also. I config crond
autorun and correct log date-format. I test it in local, log rotate successfully. the rotate-log is like : /var/log/s-2022-09-20.log
@xianhuawei @huof6829 could you try this PR in k8s?
@xianhuawei @huof6829 could you try this PR in k8s?
ok, we will run in testnet
Run smoothly in testnet.
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication