Skip to content

feat: Add support for custom timestamp format with time_format()#6

Merged
arferreira merged 2 commits intozaptech-dev:mainfrom
Rafael-0011:feat/custom-time-format
Feb 18, 2026
Merged

feat: Add support for custom timestamp format with time_format()#6
arferreira merged 2 commits intozaptech-dev:mainfrom
Rafael-0011:feat/custom-time-format

Conversation

@Rafael-0011
Copy link
Contributor

Description

This PR adds support for a custom timestamp format using the .time_format() builder method, as requested in issue #2.
I chose to implement this as a separate method, so users can enable or disable the timestamp with .timestamp(true/false) and then optionally set the format with .time_format("...").
This approach keeps the API flexible and clear, following the builder pattern.
I considered passing the format directly to .timestamp(), but separating the concerns makes the configuration more intuitive and easier to maintain.

Closes #2

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor

Checklist

  • cargo fmt ran
  • cargo clippy passes
  • cargo test passes
  • Updated README if needed

Copy link
Collaborator

@arferreira arferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good first contribution, clean and focused! Just left few things before merging could improve more.

src/logger.rs Outdated
colorize: bool,
fields: Vec<(String, String)>,
formatter: Box<dyn Formatter>,
time_format: Option<&'static str>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could store it as String

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only change the variable type, it will not have much impact. However, if you change the parameter of the time_format() method to String, it will accept both string values and literals, making the method more flexible. Would you like to make this change for greater flexibility, or keep the current approach since changing only the variable type does not affect functionality?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't affect functionality at all, but lt's unnecessarily restrictive and breaks consistency, because every other string-accepting builder method is using String.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. So, I will change the method parameter to &str, as it follows the pattern used in the project.

src/logger.rs Outdated
}

pub fn time_format(mut self, time_format: &'static str) -> Self {
self.time_format = Some(time_format);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thus we have to convert .to_string()

src/logger.rs Outdated
Comment on lines +98 to +101
match &self.time_format {
Some(fmt) => Some(Local::now().format(fmt).to_string()),
None => Some(Local::now().format("%H:%M:%S").to_string()),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make it simpler:

  let fmt = self.time_format.as_deref().unwrap_or("%H:%M:%S");
  Some(Local::now().format(fmt).to_string())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good and idiomatic

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ixe o cara ta trabalhando pra gringa agora

@arferreira
Copy link
Collaborator

BTW, I think sheen would shine on Rapina's, feel free if you want to bring for us

Copy link
Collaborator

@arferreira arferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arferreira arferreira merged commit 4c024b2 into zaptech-dev:main Feb 18, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

Allow custom timestamp format

3 participants