Skip to content

qgs: add --verbose & --debug parameters to control logging #428

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions QuoteGeneration/quote_wrapper/qgs/qgs_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "qgs_log.h"

static bool _nosyslog = false;
bool qgs_debug = false;
bool qgs_verbose = false;

void qgs_log_init(void)
{
Expand Down Expand Up @@ -68,6 +70,9 @@ void sgx_proc_log_report(int level, const char *format, ...)
// so we can always add newline
if (!format || !(*format))
return;//ignore
if (!qgs_verbose &&
level == QGS_LOG_LEVEL_INFO)
return;//ignore
va_start(ap, format);
switch(level){
case QGS_LOG_LEVEL_FATAL:
Expand Down
2 changes: 2 additions & 0 deletions QuoteGeneration/quote_wrapper/qgs/qgs_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#ifdef __cplusplus
extern "C" {
#endif/*__cplusplus*/
extern bool qgs_debug;
extern bool qgs_verbose;
void qgs_log_init(void);
void qgs_log_init_ex(bool nosyslog);
void qgs_log_fini(void);
Expand Down
12 changes: 6 additions & 6 deletions QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ typedef quote3_error_t (*sgx_ql_set_logging_callback_t)(sgx_ql_logging_callback_

void sgx_ql_logging_callback(sgx_ql_log_level_t level, const char *message) {
if (level == SGX_QL_LOG_ERROR) {
sgx_proc_log_report(1, message);
sgx_proc_log_report(1, "%s", message);

} else if (level == SGX_QL_LOG_INFO) {
sgx_proc_log_report(3, message);
sgx_proc_log_report(3, "%s", message);
}
}

Expand Down Expand Up @@ -113,8 +113,8 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
sgx_ql_set_logging_callback_t ql_set_logging_callback =
(sgx_ql_set_logging_callback_t)dlsym(p_handle, "sgx_ql_set_logging_callback");
if (dlerror() == NULL && ql_set_logging_callback) {
// Set log level to SGX_QL_LOG_ERROR
ql_set_logging_callback(sgx_ql_logging_callback, SGX_QL_LOG_ERROR);
ql_set_logging_callback(sgx_ql_logging_callback,
qgs_debug ? SGX_QL_LOG_INFO : SGX_QL_LOG_ERROR);
} else {
QGS_LOG_WARN("Failed to set logging callback for the quote provider library.\n");
}
Expand Down Expand Up @@ -355,8 +355,8 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
sgx_ql_set_logging_callback_t ql_set_logging_callback =
(sgx_ql_set_logging_callback_t)dlsym(p_handle, "sgx_ql_set_logging_callback");
if (dlerror() == NULL && ql_set_logging_callback) {
// Set log level to SGX_QL_LOG_ERROR
ql_set_logging_callback(sgx_ql_logging_callback, SGX_QL_LOG_ERROR);
ql_set_logging_callback(sgx_ql_logging_callback,
qgs_debug ? SGX_QL_LOG_INFO : SGX_QL_LOG_ERROR);
} else {
QGS_LOG_WARN("Failed to set logging callback for the quote provider library.\n");
}
Expand Down
10 changes: 8 additions & 2 deletions QuoteGeneration/quote_wrapper/qgs/server_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(int argc, const char* argv[])
unsigned long int num_threads = 0;
char *endptr = NULL;
if (argc > 4) {
cout << "Usage: " << argv[0] << "[--no-daemon] [-p=port_number] [-n=number_threads]"
cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads] [--verbose] [--debug]"
<< endl;
exit(1);
}
Expand All @@ -87,6 +87,12 @@ int main(int argc, const char* argv[])
<< endl;
no_daemon = true;
continue;
} else if (strcmp(argv[i], "--debug") == 0) {
qgs_verbose = qgs_debug = true;
continue;
} else if (strcmp(argv[i], "--verbose") == 0) {
qgs_verbose = true;
continue;
} else if (strncmp(argv[i], "-p=", 3 ) == 0) {
if (strspn(argv[i] + 3, "0123456789") != strlen(argv[i] + 3)) {
cout << "Please input valid port number" << endl;
Expand Down Expand Up @@ -114,7 +120,7 @@ int main(int argc, const char* argv[])
cout << "thread number [" << num_threads << "] found in cmdline" << endl;
continue;
} else {
cout << "Usage: " << argv[0] << "[--no-daemon] [-p=port_number] [-n=number_threads]"
cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads] [--verbose] [--debug]"
<< endl;
exit(1);
}
Expand Down