Patchwork [RESEND] lib: fwts_log_json: enable json human readable formatting (LP: #1206290)

login
register
mail settings
Submitter Colin King
Date Aug. 3, 2013, 8:57 a.m.
Message ID <1375520261-22114-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/264396/
State Accepted
Headers show

Comments

Colin King - Aug. 3, 2013, 8:57 a.m.
From: Colin Ian King <colin.king@canonical.com>

The current json log output is hard to read as a human. Enable the json
pretty printing (if libjson supports it) to make it easier for mortals to
parse by eye.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_log_json.c | 5 +++++
 1 file changed, 5 insertions(+)
Keng-Yu Lin - Aug. 5, 2013, 7:48 a.m.
On Sat, Aug 3, 2013 at 4:57 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The current json log output is hard to read as a human. Enable the json
> pretty printing (if libjson supports it) to make it easier for mortals to
> parse by eye.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_log_json.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/src/lib/src/fwts_log_json.c b/src/lib/src/fwts_log_json.c
> index a67bc3a..4ce1dfe 100644
> --- a/src/lib/src/fwts_log_json.c
> +++ b/src/lib/src/fwts_log_json.c
> @@ -216,7 +216,12 @@ static void fwts_log_close_json(fwts_log_file *log_file)
>
>         fwts_log_section_end_json(log_file);
>
> +#ifdef JSON_C_TO_STRING_PRETTY
> +       str = json_object_to_json_string_ext(
> +               json_stack[0].obj, JSON_C_TO_STRING_PRETTY);
> +#else
>         str = json_object_to_json_string(json_stack[0].obj);
> +#endif
>         if (str == NULL) {
>                 /* Let's not make this bail out as user may be logging to other files too */
>                 fprintf(stderr, "Cannot turn json object to text for output. Empty json output\n");
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Ivan Hu - Aug. 6, 2013, 5:28 a.m.
On 08/03/2013 04:57 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The current json log output is hard to read as a human. Enable the json
> pretty printing (if libjson supports it) to make it easier for mortals to
> parse by eye.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_log_json.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/src/lib/src/fwts_log_json.c b/src/lib/src/fwts_log_json.c
> index a67bc3a..4ce1dfe 100644
> --- a/src/lib/src/fwts_log_json.c
> +++ b/src/lib/src/fwts_log_json.c
> @@ -216,7 +216,12 @@ static void fwts_log_close_json(fwts_log_file *log_file)
>
>   	fwts_log_section_end_json(log_file);
>
> +#ifdef JSON_C_TO_STRING_PRETTY
> +	str = json_object_to_json_string_ext(
> +		json_stack[0].obj, JSON_C_TO_STRING_PRETTY);
> +#else
>   	str = json_object_to_json_string(json_stack[0].obj);
> +#endif
>   	if (str == NULL) {
>   		/* Let's not make this bail out as user may be logging to other files too */
>   		fprintf(stderr, "Cannot turn json object to text for output. Empty json output\n");
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_log_json.c b/src/lib/src/fwts_log_json.c
index a67bc3a..4ce1dfe 100644
--- a/src/lib/src/fwts_log_json.c
+++ b/src/lib/src/fwts_log_json.c
@@ -216,7 +216,12 @@  static void fwts_log_close_json(fwts_log_file *log_file)
 
 	fwts_log_section_end_json(log_file);
 
+#ifdef JSON_C_TO_STRING_PRETTY
+	str = json_object_to_json_string_ext(
+		json_stack[0].obj, JSON_C_TO_STRING_PRETTY);
+#else
 	str = json_object_to_json_string(json_stack[0].obj);
+#endif
 	if (str == NULL) {
 		/* Let's not make this bail out as user may be logging to other files too */
 		fprintf(stderr, "Cannot turn json object to text for output. Empty json output\n");