extentreports-java icon indicating copy to clipboard operation
extentreports-java copied to clipboard

ExtentSparkReporter. Change format of TIMESTAMP field

Open TripleG opened this issue 1 year ago • 3 comments

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?

TripleG avatar Mar 09 '24 13:03 TripleG

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

rado-o avatar Apr 02 '24 13:04 rado-o

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();
  1. 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 avatar Apr 02 '24 17:04 Pitchuka-kamalesh

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.

Pitchuka-kamalesh avatar Apr 03 '24 11:04 Pitchuka-kamalesh