Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include handler errors in the log file #377

Closed
JustAnotherArchivist opened this issue May 21, 2021 · 3 comments · Fixed by #386
Closed

Include handler errors in the log file #377

JustAnotherArchivist opened this issue May 21, 2021 · 3 comments · Fixed by #386

Comments

@JustAnotherArchivist
Copy link
Contributor

I realised today that many messages only get logged to stderr, not to the log file. In particular, this includes all errors in the handlers, e.g. errors on reading from the storage (i.e. the log.Printf calls in handlers.go). I'd like to suggest having those both on stderr and in the log file (if one is specified).

@aspacca
Copy link
Collaborator

aspacca commented May 22, 2021

I will check @JustAnotherArchivist , thanks for reporting.

@stefanbenten
Copy link
Collaborator

I would suggest to chose either stderr or log, but not both.

@aspacca
Copy link
Collaborator

aspacca commented Jul 6, 2021

We should only rely on the logger instantiated in the cmd package: https://github.com/dutchcoders/transfer.sh/blob/master/cmd/cmd.go#L294

This will either use stdout or the log file if set (

func LogFile(logger *log.Logger, s string) OptionFn {
return func(srvr *Server) {
f, err := os.OpenFile(s, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
logger.SetOutput(f)
srvr.logger = logger
}
}
func Logger(logger *log.Logger) OptionFn {
return func(srvr *Server) {
srvr.logger = logger
}
}
)

The calls to log.Printf etc should be replaced by logger.Printf etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants