Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

refactor: new api for dflog and output log to console by default #783

Merged
merged 1 commit into from
Aug 27, 2019

Conversation

inoc603
Copy link
Member

@inoc603 inoc603 commented Aug 5, 2019

Signed-off-by: inoc603 [email protected]

Ⅰ. Describe what this PR did

  1. Refactored dflog, make log initialization consistent across dfdaemon/dfclient/supernode
  2. Use natefinch/lumberjack.v2 for log rotation. It's a little different than the current approach we use, rather than rotating the same log file, it creates a new file and backup the current log file. If we still want to keep the current log rotating behavior, I can change it back.
  3. Output dfdaemon's log to stdout by default

Ⅱ. Does this pull request fix one issue?

fixes #651

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Ⅳ. Describe how to verify it

Start dfdaemon and check the console output

Ⅴ. Special notes for reviews

opts := []dflog.Option{
dflog.WithLogFile(logFilePath),
dflog.WithSign(fmt.Sprintf("%d", os.Getpid())),
dflog.WithDebug(options.Debug),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to make supernode output logs to console as an default option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. But currently there's no configuration to disable console log. Should we provide options to turn it off?

@inoc603 inoc603 force-pushed the log branch 3 times, most recently from 7b0d080 to 8c52158 Compare August 5, 2019 05:23
@codecov-io
Copy link

codecov-io commented Aug 5, 2019

Codecov Report

Merging #783 into master will increase coverage by 0.01%.
The diff coverage is 37.8%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #783      +/-   ##
==========================================
+ Coverage   39.41%   39.42%   +0.01%     
==========================================
  Files         108      108              
  Lines        6310     6288      -22     
==========================================
- Hits         2487     2479       -8     
+ Misses       3618     3603      -15     
- Partials      205      206       +1
Impacted Files Coverage Δ
cmd/supernode/app/root.go 58.33% <0%> (-1.11%) ⬇️
cmd/dfdaemon/app/init.go 0% <0%> (ø) ⬆️
cmd/dfget/app/server.go 51.21% <0%> (-8.79%) ⬇️
cmd/dfget/app/root.go 63.19% <0%> (-1.19%) ⬇️
pkg/dflog/log.go 51.48% <56.36%> (-6.77%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68ba7b4...4176763. Read the comment docs.

pkg/dflog/log.go Outdated Show resolved Hide resolved

// open log file
logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to specify the FileMode as 0644, all users can read the log file. If not, the created file's mode is relied on the os's umask. If the os's umask is 027, then the new file's mode is 0640, it means only the owner and users in same group can read the file.

Copy link
Member Author

@inoc603 inoc603 Aug 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version of lumberjack I'm using, v2.0.0 did set the file mode to 0644. However in this commit it changes the default mode to 0600. I've been using this library in production for quite a while, and it's pretty stable. If 0644 is what we want, we can keep using v2.0.0. If there's an update in the future, we can create a PR to make the default mode configurable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I find that the previous code has same problem with this pr. If we want to create a file with permission 0644 exactly, we should explicitly call syscall.Umask to set umask.

@lowzj
Copy link
Member

lowzj commented Aug 27, 2019

LGTM

@lowzj lowzj merged commit 63f099d into dragonflyoss:master Aug 27, 2019
sungjunyoung pushed a commit to sungjunyoung/Dragonfly that referenced this pull request May 8, 2022
* docs(zh-CN): remove README.md machine translation

Signed-off-by: zzy987 <[email protected]>

* docs: fixed some machine translation

Signed-off-by: zzy987 <[email protected]>

* fix: some translation

Signed-off-by: zzy987 <[email protected]>

* chore: update helm-charts

Signed-off-by: zzy987 <[email protected]>

* doc: markdown lint

Signed-off-by: zzy987 <[email protected]>

* doc: markdown lint

Signed-off-by: zzy987 <[email protected]>

* doc: markdown lint

Signed-off-by: zzy987 <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] output logs to stdout
5 participants