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/ir-parse.c b/ir-parse.c
index e599b68..ef588f1 100644
--- a/ir-parse.c
+++ b/ir-parse.c
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <string.h>
#include <json.h>
+#include <libcper/log.h>
#include <libcper/base64.h>
#include <libcper/Cper.h>
#include <libcper/cper-parse.h>
@@ -38,7 +39,7 @@
json_object *section_descriptors =
json_object_object_get(ir, "sectionDescriptors");
if (section_descriptors == NULL) {
- printf("Invalid CPER file: No section descriptors.\n");
+ cper_print_log("Invalid CPER file: No section descriptors.\n");
return;
}
int amt_descriptors = json_object_array_length(section_descriptors);
@@ -57,7 +58,7 @@
//Run through each section in turn.
json_object *sections = json_object_object_get(ir, "sections");
if (sections == NULL) {
- printf("Invalid CPER file: No sections.\n");
+ cper_print_log("Invalid CPER file: No sections.\n");
return;
}
int amt_sections = json_object_array_length(sections);
@@ -193,7 +194,8 @@
json_object_get_string(encoded),
json_object_get_string_len(encoded), &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);
free(decoded);