Implement common logging function
When used as a library, it's desirable to be able to suppress logging,
or pipe logging through a different path. This commit changes behavior
such that logging is disabled by default, and introduces 2 new methods,
cper_set_log_stdio and cper_set_log_custom.
These allow library integrators to specify their logging mode. In
practice, this also allows fuzzing to run faster by not printing errors
to the log.
Change-Id: I941476627bc9b8261ba5f6c0b2b2338fdf931dd2
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/sections/cper-section-ia32x64.c b/sections/cper-section-ia32x64.c
index fe3acca..8f84c11 100644
--- a/sections/cper-section-ia32x64.c
+++ b/sections/cper-section-ia32x64.c
@@ -11,6 +11,7 @@
#include <libcper/Cper.h>
#include <libcper/cper-utils.h>
#include <libcper/sections/cper-section-ia32x64.h>
+#include <libcper/log.h>
//Private pre-definitions.
json_object *cper_ia32x64_processor_error_info_to_ir(
@@ -99,7 +100,8 @@
sizeof(EFI_IA32_X64_PROCESS_ERROR_INFO))) {
json_object_put(error_info_array);
json_object_put(record_ir);
- printf("Invalid CPER file: Invalid processor error info num.\n");
+ cper_print_log(
+ "Invalid CPER file: Invalid processor error info num.\n");
return NULL;
}
@@ -119,7 +121,8 @@
if (remaining_size < (processor_context_info_num *
sizeof(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO))) {
json_object_put(record_ir);
- printf("Invalid CPER file: Invalid processor context info num.\n");
+ cper_print_log(
+ "Invalid CPER file: Invalid processor context info num.\n");
return NULL;
}
EFI_IA32_X64_PROCESSOR_CONTEXT_INFO *current_context_info =
@@ -210,7 +213,8 @@
break;
default:
//Unknown check information.
- printf("WARN: Invalid/unknown check information GUID found in IA32/x64 CPER section. Ignoring.\n");
+ cper_print_log(
+ "WARN: Invalid/unknown check information GUID found in IA32/x64 CPER section. Ignoring.\n");
break;
}
@@ -522,7 +526,8 @@
context_info->ArraySize,
&encoded_len);
if (encoded == NULL) {
- printf("Failed to allocate encode output buffer. \n");
+ cper_print_log(
+ "Failed to allocate encode output buffer. \n");
} else {
register_array = json_object_new_object();
json_object_object_add(register_array, "data",
@@ -802,7 +807,8 @@
break;
default:
//Unknown check information.
- printf("WARN: Invalid/unknown check information GUID found in IA32/x64 CPER section. Ignoring.\n");
+ cper_print_log(
+ "WARN: Invalid/unknown check information GUID found in IA32/x64 CPER section. Ignoring.\n");
break;
}
add_to_valid_bitfield(&ui64Type, 0);
@@ -1028,7 +1034,8 @@
int j_size = json_object_get_string_len(encoded);
UINT8 *decoded = base64_decode(j_string, j_size, &decoded_len);
if (decoded == NULL) {
- printf("Failed to allocate decode output buffer. \n");
+ cper_print_log(
+ "Failed to allocate decode output buffer. \n");
} else {
fwrite(decoded, decoded_len, 1, out);
fflush(out);