extent-framework / extentreports-java

Extent Reporting Library, Java
http://extentreports.com
Apache License 2.0
220 stars 126 forks source link

ExtentSparkReporter. Change format of TIMESTAMP field #430

Open TripleG opened 6 months ago

TripleG commented 6 months ago

I want to change the format of the TIMESTAMP field to include milliseconds as well. I tried

ExtentSparkReporter spark = new ExtentSparkReporter("test-output/Spark.html");
spark.config().setTimeStampFormat("hh:mm:ss.SSS");
extent.attachReporter(spark);

But the timestamp format does not change: image

Am I using the correct setting?

rado-o commented 5 months ago

Hey, maybe the same issue as described here: https://github.com/extent-framework/extentreports-java/issues/293?

Pitchuka-kamalesh commented 5 months ago

Hi All,

I've investigated the issue reported in comment1 and have some insights to share:

  1. The code responsible for generating the log timestamp is located in the Log.java file within the package com.aventstack.extentreports.model. Unfortunately, this code is not directly modifiable:

    private Date timestamp = Calendar.getInstance().getTime();
  2. However, there's a way to adjust the format of the log timestamp by modifying the log.ftl file found in the templates directory. Here's how you can proceed:

    File Path: src\main\resources\com\aventstack\extentreports\templates\spark\macros\log.ftl

Log.ftl: image

   <td>${log.timestamp?time?string}</td>

After change: image

To change the format to "hh:mm:ss.SSS a", replace it as follows:

   <td>${log.timestamp?time?string("format")}</td>

This is my hypothesis after modification will update the format in which the timestamp is displayed in the logs.

I will test and update everything in the next comment. Thanks, Kamalesh.

Pitchuka-kamalesh commented 5 months ago

Hi @TripleG,

I have made changes to the code and found that my earlier hypothesis was correct. Here is a screenshot of the results.

Here is the screenshot of how it looks without changing the CSS values.

After the change: image

I have two methods; one is hardcoded and the other method involves creating a variable in the package com.aventstack.extentreports.reporter.configuration and a file named AbstractConfiguration.

The First Method is shown above comment.

Second Method: Create a variable on the package com.aventstack.extentreports.reporter.configuration and a file named AbstractConfiguration.

    @Builder.Default
    private String timeFormat = "hh:mm:ss a";

and you have to change it in these files also.

  1. src/main/resources/com/aventstack/extentreports/templates/commons/commons-variables.ftl add the below code inside the <#assign> tag.
  timeFormat=config.timeFormat
  1. src/main/resources/com/aventstack/extentreports/templates/spark/macros/log.ftl please modify the below code to:
<td>${log.timestamp?time?string["${timeFormat}"]}</td>

But I discovered why the owner kept the format as default format - it looks neat and clean.

@anshooarora could you please confirm this issue, so that the issue can be closed?

Thanks,

Kamalesh.