Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExtentSparkReporter. Change format of TIMESTAMP field #430

Open
TripleG opened this issue Mar 9, 2024 · 3 comments
Open

ExtentSparkReporter. Change format of TIMESTAMP field #430

TripleG opened this issue Mar 9, 2024 · 3 comments

Comments

@TripleG
Copy link

TripleG commented Mar 9, 2024

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
Copy link

rado-o commented Apr 2, 2024

Hey,
maybe the same issue as described here: #293?

@Pitchuka-kamalesh
Copy link

Pitchuka-kamalesh commented Apr 2, 2024

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
Copy link

Pitchuka-kamalesh commented Apr 3, 2024

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 added a commit to Pitchuka-kamalesh/extentreports-java that referenced this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants