-
Notifications
You must be signed in to change notification settings - Fork 17
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
Improve logging #46
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should use https://developer.apple.com/documentation/os/os_log ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See man 3 os_log
for the usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan to update this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an issue to consider using os_log: #64
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
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