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

decoder::log: Rename PrettyLogger to StdoutLogger #766

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- [#766] `decoder::log`: Rename `PrettyLogger` to `StdoutLogger`

[#766]: https://github.com/knurling-rs/defmt/pull/766

## [v0.3.5] - 2023-06-19

- [#760]: `defmt-macros`: Upgrade to syn 2
Expand Down
6 changes: 3 additions & 3 deletions decoder/src/log/json_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use time::OffsetDateTime;

use std::io::{self, Write};

use super::{pretty_logger::PrettyLogger, DefmtRecord};
use super::{DefmtRecord, StdoutLogger};

pub(crate) struct JsonLogger {
should_log: Box<dyn Fn(&Metadata) -> bool + Sync + Send>,
host_logger: PrettyLogger,
host_logger: StdoutLogger,
}

impl Log for JsonLogger {
Expand Down Expand Up @@ -44,7 +44,7 @@ impl JsonLogger {
pub fn new(should_log: impl Fn(&Metadata) -> bool + Sync + Send + 'static) -> Box<Self> {
Box::new(Self {
should_log: Box::new(should_log),
host_logger: PrettyLogger::new_unboxed(true, |_| true),
host_logger: StdoutLogger::new_unboxed(true, |_| true),
})
}

Expand Down
6 changes: 3 additions & 3 deletions decoder/src/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//! [`defmt`]: https://crates.io/crates/defmt

mod json_logger;
mod pretty_logger;
mod stdout_logger;

use log::{Level, LevelFilter, Metadata, Record};
use serde::{Deserialize, Serialize};

use std::fmt;

use self::{json_logger::JsonLogger, pretty_logger::PrettyLogger};
use self::{json_logger::JsonLogger, stdout_logger::StdoutLogger};
use crate::Frame;

const DEFMT_TARGET_MARKER: &str = "defmt@";
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn init_logger(
should_log: impl Fn(&Metadata) -> bool + Sync + Send + 'static,
) {
log::set_boxed_logger(match json {
false => PrettyLogger::new(always_include_location, should_log),
false => StdoutLogger::new(always_include_location, should_log),
true => {
JsonLogger::print_schema_version();
JsonLogger::new(should_log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use std::{

use super::DefmtRecord;

pub(crate) struct PrettyLogger {
pub(crate) struct StdoutLogger {
always_include_location: bool,
should_log: Box<dyn Fn(&Metadata) -> bool + Sync + Send>,
/// Number of characters used by the timestamp. This may increase over time and is used to align
/// messages.
timing_align: AtomicUsize,
}

impl Log for PrettyLogger {
impl Log for StdoutLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
(self.should_log)(metadata)
}
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Log for PrettyLogger {
fn flush(&self) {}
}

impl PrettyLogger {
impl StdoutLogger {
pub fn new(
always_include_location: bool,
should_log: impl Fn(&Metadata) -> bool + Sync + Send + 'static,
Expand Down
Loading