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-pcie.c b/sections/cper-section-pcie.c
index e616728..ee8a1d9 100644
--- a/sections/cper-section-pcie.c
+++ b/sections/cper-section-pcie.c
@@ -11,6 +11,7 @@
 #include <libcper/Cper.h>
 #include <libcper/cper-utils.h>
 #include <libcper/sections/cper-section-pcie.h>
+#include <libcper/log.h>
 
 struct aer_info_registers {
 	UINT32 pcie_capability_header;
@@ -150,7 +151,8 @@
 			base64_encode((UINT8 *)pcie_error->Capability.PcieCap,
 				      60, &encoded_len);
 		if (encoded == NULL) {
-			printf("Failed to allocate encode output buffer. \n");
+			cper_print_log(
+				"Failed to allocate encode output buffer. \n");
 		} else {
 			json_object *capability = json_object_new_object();
 			json_object_object_add(capability, "data",
@@ -172,7 +174,8 @@
 		encoded = base64_encode((UINT8 *)pcie_error->AerInfo.PcieAer,
 					96, &encoded_len);
 		if (encoded == NULL) {
-			printf("Failed to allocate encode output buffer. \n");
+			cper_print_log(
+				"Failed to allocate encode output buffer. \n");
 		} else {
 			json_object_object_add(aer_capability_ir, "data",
 					       json_object_new_string_len(
@@ -341,7 +344,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 {
 			memcpy(section_cper->Capability.PcieCap, decoded,
 			       decoded_len);
@@ -363,7 +367,8 @@
 					&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->AerInfo.PcieAer, decoded,
 			       decoded_len);