From 813a451092ab364f23b399494fea97562f34838b Mon Sep 17 00:00:00 2001 From: baubakg Date: Wed, 25 Sep 2024 13:55:38 +0200 Subject: [PATCH] Adapted log-parser to include JSON in the commandline execution --- README.md | 3 +- .../tests/logparser/RunLogParser.java | 30 ++++++++++++------- .../tests/logparser/utils/RunArguments.java | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 532c6e0..ac23dcf 100644 --- a/README.md +++ b/README.md @@ -456,7 +456,7 @@ java -jar log-parser-1.11.0.jar --startDir=/path/to/logs --parseDefinition=/path You can provide additional information such as: * `--fileFilter` : The wildcard used for selecting the log files. The default value is *.log -* `--reportType` : The format of the report. The allowed values are currently HTML & CSV. The default value is HTML +* `--reportType` : The format of the report. The allowed values are currently HTML, JSON & CSV. The default value is HTML * `--reportFileName` : The name of the report file. By default, this is the name of the Parse Definition name suffixed with '-export' * `--reportName` : The report title as show in an HTML report. By default, the title includes the Parse Definition name @@ -472,6 +472,7 @@ All reports are stored in the directory `log-parser-reports/export/`. - **(new feature)** [#138](https://github.com/adobe/log-parser/issues/138) We now have the possibility of anonymizing log data during parsing. For more information please read the section on [Anonymizing Data](#anonymizing-data). - **(new feature)** [#117](https://github.com/adobe/log-parser/issues/117) You can now include the file name in the result of the analysis. - **(new feature)** [#141](https://github.com/adobe/log-parser/issues/141) You can now export a LogData as a table in a HTML file. +- **(new feature)** [#173](https://github.com/adobe/log-parser/issues/173) You can now export a LogData as a JSON file. - **(new feature)** [#123](https://github.com/adobe/log-parser/issues/123) We now log the total number and size of the parsed files. - [#110](https://github.com/adobe/log-parser/issues/110) Moved to Java 11 - [#169](https://github.com/adobe/log-parser/issues/169) We only keep one Parse Definition entry with the same title in a Parse Definition. diff --git a/src/main/java/com/adobe/campaign/tests/logparser/RunLogParser.java b/src/main/java/com/adobe/campaign/tests/logparser/RunLogParser.java index 738e40c..793861d 100644 --- a/src/main/java/com/adobe/campaign/tests/logparser/RunLogParser.java +++ b/src/main/java/com/adobe/campaign/tests/logparser/RunLogParser.java @@ -64,18 +64,26 @@ public static void main(String[] in_args) throws StringParseException { l_targetSDKClass); //Generate Report - if (RunArguments.REPORT_FORMAT.fetchValue(in_args).equalsIgnoreCase("CSV")) { - l_logData.exportLogDataToCSV(RunArguments.REPORT_FILENAME.fetchValue(in_args, - l_parseDefinition.fetchEscapedTitle() + "-export.csv")); - } else if (RunArguments.REPORT_FORMAT.fetchValue(in_args).equalsIgnoreCase("HTML")) { - l_logData.exportLogDataToHTML( - RunArguments.REPORT_NAME.fetchValue(in_args, l_parseDefinition.getTitle()), - RunArguments.REPORT_FILENAME.fetchValue(in_args, - l_parseDefinition.fetchEscapedTitle() + "-export.html")); - } else { - System.err.println("The report format " + RunArguments.REPORT_FORMAT.fetchValue(in_args) - + " is not supported."); + switch (RunArguments.REPORT_FORMAT.fetchValue(in_args).toUpperCase()) { + case "CSV": + l_logData.exportLogDataToCSV(RunArguments.REPORT_FILENAME.fetchValue(in_args, + l_parseDefinition.fetchEscapedTitle() + "-export.csv")); + break; + case "HTML": + l_logData.exportLogDataToHTML( + RunArguments.REPORT_NAME.fetchValue(in_args, l_parseDefinition.getTitle()), + RunArguments.REPORT_FILENAME.fetchValue(in_args, + l_parseDefinition.fetchEscapedTitle() + "-export.html")); + break; + case "JSON": + l_logData.exportLogDataToJSON(RunArguments.REPORT_FILENAME.fetchValue(in_args, + l_parseDefinition.fetchEscapedTitle() + "-export.json")); + break; + default: + System.err.println("The report format " + RunArguments.REPORT_FORMAT.fetchValue(in_args) + + " is not supported."); } + } } diff --git a/src/main/java/com/adobe/campaign/tests/logparser/utils/RunArguments.java b/src/main/java/com/adobe/campaign/tests/logparser/utils/RunArguments.java index cc42285..12484f2 100644 --- a/src/main/java/com/adobe/campaign/tests/logparser/utils/RunArguments.java +++ b/src/main/java/com/adobe/campaign/tests/logparser/utils/RunArguments.java @@ -21,7 +21,7 @@ public enum RunArguments { "The SDK class to be used for transforming the log data to objects. It is just the class name.", "com.adobe.campaign.tests.logparser.core.GenericEntry"), REPORT_FORMAT("reportType", false, - "The format of the report. The allowed values are currently HTML & CSV.", "HTML"), + "The format of the report. The allowed values are currently HTML, JSON & CSV.", "HTML"), REPORT_FILENAME("reportFileName", false, "The name of the report file. By default, this is the name of the Parse Definition name suffixed with '-export'", ""), REPORT_NAME("reportName", false, "The report title as show in an HTML report. By default the title includes the Parse Definition name", ""),