Skip to content

Commit 53eaf26

Browse files
committed
refactor(log): use time macro
1 parent 60fc35d commit 53eaf26

3 files changed

Lines changed: 9 additions & 16 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/log/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ thiserror = { workspace = true }
3131
serde_repr = "0.1"
3232
byte-unit = "5"
3333
log = { workspace = true, features = ["kv_unstable"] }
34-
time = { version = "0.3", features = ["formatting", "local-offset"] }
34+
time = { version = "0.3", features = ["formatting", "local-offset", "macros"] }
3535
fern = "0.7"
3636
tracing = { workspace = true, optional = true }
3737

plugins/log/src/lib.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ use tauri::{
2727
Manager, Runtime,
2828
};
2929
use tauri::{AppHandle, Emitter};
30+
use time::{macros::format_description, OffsetDateTime};
3031

3132
pub use fern;
32-
use time::OffsetDateTime;
3333

3434
pub const WEBVIEW_TARGET: &str = "webview";
3535

@@ -277,9 +277,7 @@ pub struct Builder {
277277
impl Default for Builder {
278278
fn default() -> Self {
279279
#[cfg(desktop)]
280-
let format =
281-
time::format_description::parse("[[[year]-[month]-[day]][[[hour]:[minute]:[second]]")
282-
.unwrap();
280+
let format = format_description!("[[[year]-[month]-[day]][[[hour]:[minute]:[second]]");
283281
let dispatch = fern::Dispatch::new().format(move |out, message, record| {
284282
out.finish(
285283
#[cfg(mobile)]
@@ -318,9 +316,7 @@ impl Builder {
318316
pub fn timezone_strategy(mut self, timezone_strategy: TimezoneStrategy) -> Self {
319317
self.timezone_strategy = timezone_strategy.clone();
320318

321-
let format =
322-
time::format_description::parse("[[[year]-[month]-[day]][[[hour]:[minute]:[second]]")
323-
.unwrap();
319+
let format = format_description!("[[[year]-[month]-[day]][[[hour]:[minute]:[second]]");
324320
self.dispatch = self.dispatch.format(move |out, message, record| {
325321
out.finish(format_args!(
326322
"{}[{}][{}] {}",
@@ -417,9 +413,7 @@ impl Builder {
417413

418414
#[cfg(feature = "colored")]
419415
pub fn with_colors(self, colors: fern::colors::ColoredLevelConfig) -> Self {
420-
let format =
421-
time::format_description::parse("[[[year]-[month]-[day]][[[hour]:[minute]:[second]]")
422-
.unwrap();
416+
let format = format_description!("[[[year]-[month]-[day]][[[hour]:[minute]:[second]]");
423417

424418
let timezone_strategy = self.timezone_strategy.clone();
425419
self.format(move |out, message, record| {
@@ -601,11 +595,9 @@ fn get_log_file_path(
601595
let to = dir.as_ref().join(format!(
602596
"{}_{}.log",
603597
file_name,
604-
timezone_strategy
605-
.get_now()
606-
.format(&time::format_description::parse(
607-
"[year]-[month]-[day]_[hour]-[minute]-[second]"
608-
)?)?,
598+
timezone_strategy.get_now().format(&format_description!(
599+
"[year]-[month]-[day]_[hour]-[minute]-[second]"
600+
))?,
609601
));
610602
if to.is_file() {
611603
// designated rotated log file name already exists

0 commit comments

Comments
 (0)