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-cxl-protocol.c b/sections/cper-section-cxl-protocol.c
index 1a9b33b..ebf3648 100644
--- a/sections/cper-section-cxl-protocol.c
+++ b/sections/cper-section-cxl-protocol.c
@@ -10,6 +10,7 @@
 #include <libcper/Cper.h>
 #include <libcper/cper-utils.h>
 #include <libcper/sections/cper-section-cxl-protocol.h>
+#include <libcper/log.h>
 
 //Converts a single CXL protocol error CPER section into JSON IR.
 json_object *cper_section_cxl_protocol_to_ir(const UINT8 *section, UINT32 size)
@@ -135,7 +136,8 @@
 			(UINT8 *)cxl_protocol_error->CapabilityStructure.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");
 			json_object_put(section_ir);
 
 			return NULL;
@@ -190,7 +192,8 @@
 					&encoded_len);
 
 		if (encoded == NULL) {
-			printf("Failed to allocate encode output buffer. \n");
+			cper_print_log(
+				"Failed to allocate encode output buffer. \n");
 			json_object_put(section_ir);
 			return NULL;
 		}
@@ -295,7 +298,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->CapabilityStructure.PcieCap,
 				       decoded, decoded_len);
@@ -338,7 +342,8 @@
 					json_object_get_string_len(encodedsrc),
 					&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);
@@ -353,7 +358,8 @@
 					json_object_get_string_len(encodederr),
 					&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);