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-dmar-iommu.c b/sections/cper-section-dmar-iommu.c
index c411cf2..df22ce0 100644
--- a/sections/cper-section-dmar-iommu.c
+++ b/sections/cper-section-dmar-iommu.c
@@ -11,6 +11,7 @@
 #include <libcper/Cper.h>
 #include <libcper/cper-utils.h>
 #include <libcper/sections/cper-section-dmar-iommu.h>
+#include <libcper/log.h>
 
 //Converts a single IOMMU specific DMAr CPER section into JSON IR.
 json_object *cper_section_dmar_iommu_to_ir(const UINT8 *section, UINT32 size)
@@ -40,7 +41,7 @@
 	char *encoded = base64_encode((UINT8 *)iommu_error->EventLogEntry, 16,
 				      &encoded_len);
 	if (encoded == NULL) {
-		printf("Failed to allocate encode output buffer. \n");
+		cper_print_log("Failed to allocate encode output buffer. \n");
 
 		return NULL;
 	}
@@ -55,7 +56,7 @@
 	encoded = base64_encode((UINT8 *)iommu_error->DeviceTableEntry, 32,
 				&encoded_len);
 	if (encoded == NULL) {
-		printf("Failed to allocate encode output buffer. \n");
+		cper_print_log("Failed to allocate encode output buffer. \n");
 		return NULL;
 	}
 	json_object_object_add(section_ir, "deviceTableEntry",
@@ -103,7 +104,7 @@
 				       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 {
 		memcpy(section_cper->EventLogEntry, decoded, decoded_len);
 		free(decoded);
@@ -116,7 +117,7 @@
 				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 {
 		memcpy(section_cper->DeviceTableEntry, decoded, decoded_len);
 		free(decoded);