enhance trace API adding verbosity levels and automatic func+file+line output#9110
enhance trace API adding verbosity levels and automatic func+file+line output#9110DDvO wants to merge 4 commits intoopenssl:masterfrom
Conversation
There was a problem hiding this comment.
Thank you for your enhancements to the trace api. When the trace api was introduced, I also considered having trace categories and trace levels. But then I discarded the idea again because I thought the classification might be too fine grained. But if you think it's a useful feature, I don't mind.
There are however some details about your implementation which I dislike. It's mostly about consistency of naming and of implementation.
First of all, please be consistent with your naming: Either call it "trace level" or "trace verbosity", but not both. (I prefer the former.) So the function should be named
const char *OSSL_trace_get_level_name(int level)Also, I don't see the inverse function.
int OSSL_trace_get_level_num(const char *name)In fact, there is absolutely no reason to implement those two functions completely differently than the existing functions
const char *OSSL_trace_get_category_name(int num);
int OSSL_trace_get_category_num(const char *name);The implementations can be made completely analogous, it's just copy&paste&rename of the following code, then add your level names.
Lines 114 to 155 in 37ca204
And most importantly: adding an api for the trace level, but completely neglecting the level parameter in the OSSL_TRACEX(...) convenience macros is an absolute no-go. If it's a useful parameter, then it MUST be available through the macros, too.
crypto/trace.c
Outdated
| #endif | ||
| } | ||
|
|
||
| const char *OSSL_trace_get_verbosity_name(int level) |
There was a problem hiding this comment.
It should be called
const char *OSSL_trace_get_level_name(int level)in order to be consistent with the names of the constants.
| * TRACE LEVEL AND VERBOSITY | ||
| */ | ||
|
|
||
| # define OSSL_TRACE_LEVEL_UNDEFINED 0 |
There was a problem hiding this comment.
I see no use in having an 'undefined' trace level. Normally, I would call it 'off' or 'disabled', but since trace categories are enabled by attaching channels to them, a 'disabled' level does not make sense IMHO.
|
|
||
| # define OSSL_TRACE(category, text) \ | ||
| OSSL_TRACEV(category, (trc_out, "%s", text)) | ||
| OSSL_TRACEV(category, UNDEFINED, (trc_out, "%s", text)) |
There was a problem hiding this comment.
The trace level MUST be part of the trace macros, too. Otherwise, the addition of trace levels does not make sense.
include/openssl/trace.h
Outdated
| # if defined DEBUG && !defined NDEBUG | ||
| # define OSSL_TRACE_LEVEL_DEFAULT OSSL_TRACE_LEVEL_DEBUG | ||
| # else | ||
| # define OSSL_TRACE_LEVEL_DEFAULT OSSL_TRACE_LEVEL_INFO |
There was a problem hiding this comment.
Please use 'info' as default level regardless of DEBUG/NDEBUG.
|
Please also note that the OPENSSL(1) command supports setting the trace categories via environment variable. OPENSSL_TRACE=name,...
Enable tracing output of OpenSSL library, by name. This output will only make sense if you know OpenSSL internals well. Also, it might
not give you any output at all, depending on how OpenSSL was built.
The value is a comma separated list of names, with the following available:
TRACE
The tracing functionality.
TLS General SSL/TLS.
TLS_CIPHER
SSL/TLS cipher.
...I don't think it is necessary to enhance the syntax of the For a starting point, see Lines 215 to 240 in 37ca204 |
| "ssl-trace" => "default", | ||
| "ssl3" => "default", | ||
| "ssl3-method" => "default", | ||
| "trace" => "default", |
There was a problem hiding this comment.
The trace api is disabled by default for good reasons, see 6bc62a6, #8474 and #8472. Please don't change that.
I would accept if 'debug' woud imply 'trace', but I don't see a precedent in the Configure file, i.e., there is no @enable_cascades analogous to @disable_cascades.
Lines 474 to 478 in 2c8a407
There was a problem hiding this comment.
I would accept if 'debug' would imply 'trace'
I'm not even sure whether such an automatism needs to be added at all. Since most people either rely on command line history or have personal configure scripts, the trace option can easily be added to the command line.
There was a problem hiding this comment.
DO NOT ENABLE TRACE BY DEFAULT.
There was a problem hiding this comment.
Thank you for this feedback.
David is on vacation the next two weeks, but he will change this as soon as possible.
There was a problem hiding this comment.
No hurry. I‘ll be on vacation, too.
|
I had already started doing the requested changes, but meanwhile I wonder if its is worth continuing. As mentioned, due to the trace facility being disabled in default/production builds, What do you (all) think, should we nevertheless continue as indicated above, for potential benefit to other parts/users of libcrypto? |
|
BTW, this PR is also related to #9058. |
|
As mentioned above and discussed about two weeks ago in the context of the CMP contribution chunk 4: |
This is a by-product of the CMP contribution. As discussed with @mattcaswell for the preview of chunk 4: mpeylo#178 (comment) I've carved this out as an independent PR. It is going to be used first in #9107.
This adds
I have not yet updated the documentation files accordingly because I thought it would be more efficient to collect some feedback, decide on any further changes, and then implement them along with the due extensions of the respective
.podfiles.The use of the severity level functions should be self-explanatory.
Log messages can be produced like this:
The output, as far as enabled according to the level, looks like this:
It turns out that the trace facility of OpenSSL is disabled globally by default and needs to be enabled explicitly via the enable-trace configuration option. This is not adequate when using the trace API for error and warning output.
What I propose instead is to enable its inclusion by default (as done in this PR in
Configiure)while taking, e.g.,
OSSL_TRACE_LEVEL_INFOas the default level of verbosity. In this way detailed (trace-level and debugging) output remains disabled while alert, error, warning, and info output is enabled.When
DEBUGis defined andNDEBUGis not defined, the default becomesOSSL_TRACE_LEVEL_DEBUG.Using the new code in
trace.handtrace.c, the level of verbosity can be adapted per category.