-
Notifications
You must be signed in to change notification settings - Fork 745
Add the ability to prepend encoded log severity in the log message #1327
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
Conversation
userspace/libsinsp/logger.cpp
Outdated
|
||
namespace { | ||
// All severity strings should be ENCODE_LEN chars long | ||
const char* sev_levels[] = { |
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.
all caps preferred...
SEVERITY_LEVELS
userspace/libsinsp/logger.h
Outdated
@@ -95,10 +98,16 @@ class SINSP_PUBLIC sinsp_logger | |||
char* format(severity sev, const char* fmt, ...); | |||
char* format(const char* fmt, ...); | |||
|
|||
// Returns the decoded severity or SEV_MAX+1 for errors. | |||
// len is set to the length of the severity string on success | |||
// and 0 in case of errors |
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.
Change to doxy style...
/**
* This is my stuff
*/
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 don't see this returning SEV_MAX+1 anywhere
userspace/libsinsp/logger.cpp
Outdated
for(size_t i = 1; i <= SEV_MAX; ++i) | ||
{ | ||
uint64_t level = *((uint64_t*) sev_levels[i]); | ||
if(msg_level == level) |
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 is fine, but not convinced it buys us much vs just a string compare
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.
Even with a hardcoded length of 8, the strncmp isn't optimized out, while the pointer cast (which I changed to a memcpy in the meantime to avoid alignment issues) gets compiled down to cmp reg, [reg]
:
Either way, this is nowhere near the hot path (hopefully) so we'll be fine with the strncmp. Thoughts?
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.
Settled on using strncmp.
1d77a0b
to
5e2b1d3
Compare
f873b5e
to
7b20b69
Compare
7b20b69
to
d3e6abd
Compare
d3e6abd
to
f5f9d16
Compare
f5f9d16
to
ab05eaf
Compare
ab05eaf
to
ce04f3a
Compare
Basically #1266 with some changes, on top of the
nfs
branch, so please review only the last commit (the rest is in separate PRs already and should be merged before this)