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

log: not rotate log file when startup #926

Merged
merged 1 commit into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/dfdaemon/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func initLogger(cfg config.Properties) error {
dflog.WithLogFile(logFilePath),
dflog.WithSign(fmt.Sprintf("%d", os.Getpid())),
dflog.WithDebug(cfg.Verbose),
dflog.WithConsole(),
}

logrus.Debugf("use log file %s", logFilePath)
Expand Down
15 changes: 8 additions & 7 deletions dfget/core/downloader/p2p_downloader/p2p_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,14 @@ func (p2p *P2PDownloader) Run() error {
} else if code == constants.CodePeerFinish {
p2p.finishTask(response, clientWriter)
return nil
} else if code == constants.CodePeerWait {
continue
}

logrus.Warnf("request piece result:%v", response)
if code == constants.CodeSourceError {
p2p.cfg.BackSourceReason = config.BackSourceReasonSourceError
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant else.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not redundant. It makes the warn log only outputted when getting an unexpected response code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you are right. Sorry for not have a look at the code carefully.

logrus.Warnf("request piece result:%v", response)
if code == constants.CodePeerWait {
continue
}
if code == constants.CodeSourceError {
p2p.cfg.BackSourceReason = config.BackSourceReasonSourceError
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/dflog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func WithLogFile(f string) Option {
if logger := getLumberjack(l); logger == nil {
l.SetOutput(&lumberjack.Logger{
Filename: f,
MaxSize: 20, // mb
MaxSize: 40, // mb
Copy link
Contributor

Choose a reason for hiding this comment

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

make it configurable? WDYT? And so do with the MaxBackups.

Copy link
Member Author

Choose a reason for hiding this comment

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

agree. There's already a function named WithMaxSizeMB to configure MaxSize. It's better to open a new pr to implement this especially make the supernode's log configurable.

MaxBackups: 1,
})
} else {
Expand Down Expand Up @@ -124,9 +124,6 @@ func Init(l *logrus.Logger, opts ...Option) error {
return err
}
}
if logger, ok := l.Out.(*lumberjack.Logger); ok {
return logger.Rotate()
}
return nil
}

Expand Down