-
Notifications
You must be signed in to change notification settings - Fork 1
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
logging #74
Comments
@paddlesteamer I think it would make sense to first decide where this If we're handle logging from the main package only, we could come up with our own simple helper function instead of introducing a new dependency. Here's a very simple version of the helper function: func log(msg, level string) {
// check verbosity level from config
// if verbose, write debug logs too, skip them otherwise
// if error, write to os.Stderr
// write to os.Stdout otherwise
}
func info(msg string) {
log(msg, "info")
}
func error(msg string) {
log(msg, "error")
}
... |
I think we should use it everywhere. For example, it's not possible to log |
@paddlesteamer What I really meant was that maybe we could just get rid of debug logs altogether. I agree that we can use a 3rd party dependency if we decide to keep debug logs though 👍 The downside of writing info/debug logs is that it could take a lot of space in the user's machine in the long run, and they usually do not make sense to the user anyway. Info/debug logs are for developers only, so it feels kind of wrong to introduce a dependency to our internal packages just so that we can print stuff to the console for development purposes. What I'd do instead is, I would just delete all the existing debug/print lines that are not helpful to the user, and add them temporarily (without committing) while debugging the app. This is just my personal opinion though 🙂 Another approach could be that we just stop using Let me know what you think! The above comments are just me thinking out loud 😄 |
Info/Debug logs are usually filtered in the releases but still kept in the binaries and could be enabled by --debug option or some interface in the program. It is useful for understanding the errors the users have. That's why a lot of popular programs have debug options in their releases. Also, they're good for developers who want to understand how code works. For example, did you know you can run google chrome with debugging and logging enabled? Or firefox? I think you could find more if you search open source programs. That's why I think we should keep them. And it doesn't needs to be logged on file, it may output to the console just with log levels. I don't mean logging like nginx does but it's best practice to have debug logs. |
@paddlesteamer This is actually similar to what I proposed in the end, but with multiple log levels:
It sounds reasonable to use a log package so that we have multiple levels but not write anything to a file. |
So the question is which logging library then? |
I liked https://github.com/op/go-logging and https://github.com/sirupsen/logrus but even though logrus is more handsome it's verbose (needs fields specified everytime) so I'm voting for go-logging. ...or logrus with a wrapper :) |
@paddlesteamer So my vote goes to logrus. |
logrus it is. |
@paddlesteamer To my understanding, you pass fields only if you want to. |
Yeah it seems so |
The package
log
is very limited. Only hasPrint
,Fatal
,Panic
methods and I think the usage ofFatal
andPanic
should be avoided.With
fmt
, we get to separatestdin
andstderr
outputs but still, it would be nice to have more indicators on logs.So I suggest using one of the logging libraries here. It would be nice to have
debug
,info
,warning
anderror
levels.debug
is for verbose messages like the ones in thefs.go
:cloudstash/internal/fs/fs.go
Lines 27 to 29 in 928046f
info
should be used for information obviously :D. We don't have those in the code right now but I think we can use it for the messages like 'file x is uploaded to y'.warning
should be used for handled errors. For example, the error here is handled:cloudstash/internal/manager/manager.go
Lines 345 to 349 in 928046f
We can log this error as a
warning
where it returned.error
is for fatal errors that shouldn't happen. There we can log aserror
and do a clean exit (unmount, wait for ongoing network operations, etc.)The text was updated successfully, but these errors were encountered: