Improve logging#46
Conversation
| #define INFOF(fmt, ...) fprintf(stderr, "INFO | " fmt "\n", __VA_ARGS__) | ||
| #define ERROR(msg) fprintf(stderr, "ERROR| " msg "\n") | ||
| #define ERRORF(fmt, ...) fprintf(stderr, "ERROR| " fmt "\n", __VA_ARGS__) | ||
| #define ERRORN(name) ERRORF(name ": %s", strerror(errno)) |
There was a problem hiding this comment.
This should move to log.h so we can split the to code to multiple files and use consistent logging.
There was a problem hiding this comment.
I guess we should use https://developer.apple.com/documentation/os/os_log ?
There was a problem hiding this comment.
See man 3 os_log for the usage
There was a problem hiding this comment.
Sure, I'll try this.
But I think we should keep the logging macros so it is easy to change the logging backend later.
There was a problem hiding this comment.
Do you plan to update this?
There was a problem hiding this comment.
What I have here was good enough for testing and fixing various issue, and I did not have time to check this direction so far.
I can update with with the version I run locally on top of current master, and we can add an issue to consider os_log.
We anyway need to add timestamps, using os_log will avoid this work.
d8500a8 to
f28945a
Compare
- Log everything to stderr - this has many advantages: much easier to
understand what happened before errors, much easier to understand the
daemon state, since stderr is line buffered, so events (e.g. start,
stop, connect, disconnect) are logged immediately. Easier to get logs
from users.
- Replace fprintf and printf with logging macros (ERRORF, ERROR, INFO)
- Replace perror with ERRORN, showing the same output an error log.
- Use prefix for all logs ("DEBUG|", "INFO |", "ERROR|") to make the
meaning of the message clear, and make all log message
aligned nicely.
- Remove unneeded log for vmnet_return_t when we get VMNET_SUCCESS
- Replace print_vmnet_status() with vmnet_strerror() returning readable
error name. Callers use ERRORF() to log the vmnet function name,
return value and error name.
- Log socket length when it is too long
- Log the signal name and number
- Don't use perror() for logging errors from function snot setting errno
- Don't log same error twice (once in a function, second in the caller)
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
|
Opened #70 to update docs/launchd configuration. |
This does not fix all the issues mentioned in #43 but prepare the infrastructure. With these changes adding timestamps for all logs is a trivial change.
understand what happened before errors, much easier to understand the
daemon state, since stderr is line buffered, so events (e.g. start,
stop, connect, disconnect) are logged immediately. Easier to get logs
from users.
meaning of the message clear, and make all log message
aligned nicely.
error name. Callers use ERRORF() to log the vmnet function name,
return value and error name.
Example log with this change