Skip to content

Commit 8636efd

Browse files
committed
qgs: add --verbose & --debug parameters to control logging
Currently qgs prints all log messages to syslog or stderr unconditionally, even those at QGS_LOG_LEVEL_INFO. At the same time it hardcodes SGX_QL_LOG_ERROR for the quote provider library making it impossible to debug that part of the code. This adds --verbose and --debug parameters to QGS with the following behaviour * Messages from QGS code at QGS_LOG_LEVEL_INFO are discarded unless --verbose is set. This makes QGS quiet by default, only printing warnings/errors. * Messages from the quote provider library are requested at SGX_QL_LOG_INFO instead of SGX_QL_LOG_ERROR if --debug is set. This output is very volumous, dumping HTTP request and response info, hence putting it behind --debug, instead of enabling it with the former --verbose flag. * Enabling --debug will imply --verbose, so setting both is redundant, albeit harmless Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
1 parent fb78693 commit 8636efd

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

QuoteGeneration/quote_wrapper/qgs/qgs_log.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "qgs_log.h"
3737

3838
static bool _nosyslog = false;
39+
bool qgs_debug = false;
40+
bool qgs_verbose = false;
3941

4042
void qgs_log_init(void)
4143
{
@@ -68,6 +70,9 @@ void sgx_proc_log_report(int level, const char *format, ...)
6870
// so we can always add newline
6971
if (!format || !(*format))
7072
return;//ignore
73+
if (!qgs_verbose &&
74+
level == QGS_LOG_LEVEL_INFO)
75+
return;//ignore
7176
va_start(ap, format);
7277
switch(level){
7378
case QGS_LOG_LEVEL_FATAL:

QuoteGeneration/quote_wrapper/qgs/qgs_log.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#ifdef __cplusplus
4141
extern "C" {
4242
#endif/*__cplusplus*/
43+
extern bool qgs_debug;
44+
extern bool qgs_verbose;
4345
void qgs_log_init(void);
4446
void qgs_log_init_ex(bool nosyslog);
4547
void qgs_log_fini(void);

QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
113113
sgx_ql_set_logging_callback_t ql_set_logging_callback =
114114
(sgx_ql_set_logging_callback_t)dlsym(p_handle, "sgx_ql_set_logging_callback");
115115
if (dlerror() == NULL && ql_set_logging_callback) {
116-
// Set log level to SGX_QL_LOG_ERROR
117-
ql_set_logging_callback(sgx_ql_logging_callback, SGX_QL_LOG_ERROR);
116+
ql_set_logging_callback(sgx_ql_logging_callback,
117+
qgs_debug ? SGX_QL_LOG_INFO : SGX_QL_LOG_ERROR);
118118
} else {
119119
QGS_LOG_WARN("Failed to set logging callback for the quote provider library.\n");
120120
}
@@ -355,8 +355,8 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
355355
sgx_ql_set_logging_callback_t ql_set_logging_callback =
356356
(sgx_ql_set_logging_callback_t)dlsym(p_handle, "sgx_ql_set_logging_callback");
357357
if (dlerror() == NULL && ql_set_logging_callback) {
358-
// Set log level to SGX_QL_LOG_ERROR
359-
ql_set_logging_callback(sgx_ql_logging_callback, SGX_QL_LOG_ERROR);
358+
ql_set_logging_callback(sgx_ql_logging_callback,
359+
qgs_debug ? SGX_QL_LOG_INFO : SGX_QL_LOG_ERROR);
360360
} else {
361361
QGS_LOG_WARN("Failed to set logging callback for the quote provider library.\n");
362362
}

QuoteGeneration/quote_wrapper/qgs/server_main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int main(int argc, const char* argv[])
7575
unsigned long int num_threads = 0;
7676
char *endptr = NULL;
7777
if (argc > 4) {
78-
cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads]"
78+
cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads] [--verbose] [--debug]"
7979
<< endl;
8080
exit(1);
8181
}
@@ -87,6 +87,12 @@ int main(int argc, const char* argv[])
8787
<< endl;
8888
no_daemon = true;
8989
continue;
90+
} else if (strcmp(argv[i], "--debug") == 0) {
91+
qgs_verbose = qgs_debug = true;
92+
continue;
93+
} else if (strcmp(argv[i], "--verbose") == 0) {
94+
qgs_verbose = true;
95+
continue;
9096
} else if (strncmp(argv[i], "-p=", 3 ) == 0) {
9197
if (strspn(argv[i] + 3, "0123456789") != strlen(argv[i] + 3)) {
9298
cout << "Please input valid port number" << endl;
@@ -114,7 +120,7 @@ int main(int argc, const char* argv[])
114120
cout << "thread number [" << num_threads << "] found in cmdline" << endl;
115121
continue;
116122
} else {
117-
cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads]"
123+
cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads] [--verbose] [--debug]"
118124
<< endl;
119125
exit(1);
120126
}

0 commit comments

Comments
 (0)