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

Customization of the timestamp format #311

Closed
rdewaele opened this issue May 17, 2022 · 4 comments · Fixed by #313
Closed

Customization of the timestamp format #311

rdewaele opened this issue May 17, 2022 · 4 comments · Fixed by #313
Assignees
Labels
enhancement New feature or request feature-request A request for new functionality
Milestone

Comments

@rdewaele
Copy link

Is your feature request related to a problem? Please describe.
The current timestamp format (e.g. [2022-05-17 00:08:36Z]) does not have sub-second timing information, which limits the diagnostic potential of the timestamp.

Describe the solution you'd like
If customization of the log format is currently possible, I missed it.
In this event, I would like to both apologize and suggest adding an example describing this use-case.

The following solutions have crossed my mind:

  • The problem is my ignorance, in which case I refer to the statement above.
  • A hard-coded format change seems adequate, but perhaps a missed opportunity.
  • Customization of the timestamp format, either through code or configuration.
  • Customization of the log format as a whole sounds like a nice bonus.

Describe alternatives you've considered
Adding timestamps to the log messages themselves is of course functional, but rather inelegant.
( Okay, I'll admit that this issue is hardly a blocker, but ... elegance! 😅 . )

Thank you for your consideration, and this very useful library.

@martincostello martincostello self-assigned this May 17, 2022
@martincostello martincostello added the enhancement New feature or request label May 17, 2022
@martincostello martincostello added this to the v0.3.0 milestone May 17, 2022
martincostello added a commit that referenced this issue May 17, 2022
Support customising the format of the timestamps.
Resolves #311.
@martincostello
Copy link
Owner

Thanks for your suggestion @rdewaele! I've opened a PR to implement this in #313.

Could you take a look and see if it would work as you'd envisioned? You'd be able to configure a different format for the timestamps like this:

var options = new XUnitLoggerOptions()
{
Filter = (_, level) => level >= LogLevel.Error,
TimestampFormat = "yyyy-MM-dd HH:mm:ss.fff",
};
var logger = BootstrapFactory((builder) => builder.AddXUnit(mock.Object, () => options));

The default behaviour would be the same as it is in the existing versions, which is to use the "u" format string.

@martincostello martincostello added the feature-request A request for new functionality label May 17, 2022
@rdewaele
Copy link
Author

Thanks a lot for the incredibly quick implementation. I will be experimenting with it today.

Thanks!

@rdewaele
Copy link
Author

This implementation covers all my (current ;-)) use-cases, so I am a happy camper. 👍

Thanks again. :-)

@martincostello
Copy link
Owner

Great thanks, I'll release this to NuGet later on today.

martincostello added a commit that referenced this issue May 22, 2022
Support customising the format of the timestamps.
Resolves #311.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature-request A request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants