Skip to content

Commit 2445e10

Browse files
refactor(log): use time macro (#2604)
1 parent 4cd6250 commit 2445e10

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

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
"{}[{}][{}] {}",
@@ -416,9 +412,7 @@ impl Builder {
416412

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

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

0 commit comments

Comments
 (0)