Skip to content
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
9 changes: 4 additions & 5 deletions src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ use log::Record;
mod humantime;
#[cfg(feature = "kv")]
mod kv;
pub(crate) mod writer;

#[cfg(feature = "color")]
pub use anstyle as style;
Expand All @@ -80,10 +79,10 @@ pub use anstyle as style;
pub use self::humantime::Timestamp;
#[cfg(feature = "kv")]
pub use self::kv::*;
pub use self::writer::Target;
pub use self::writer::WriteStyle;
pub use crate::writer::Target;
pub use crate::writer::WriteStyle;

use self::writer::{Buffer, Writer};
use crate::writer::{Buffer, Writer};

/// Formatting precision of timestamps.
///
Expand Down Expand Up @@ -650,7 +649,7 @@ mod tests {
}

fn formatter() -> Formatter {
let writer = writer::Builder::new()
let writer = crate::writer::Builder::new()
.write_style(WriteStyle::Never)
.build();

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
#![warn(clippy::print_stdout)]

mod logger;
mod writer;

pub mod fmt;

Expand Down
2 changes: 1 addition & 1 deletion src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{borrow::Cow, cell::RefCell, env, io};
use log::{LevelFilter, Log, Metadata, Record, SetLoggerError};

use crate::fmt;
use crate::fmt::writer::{self, Writer};
use crate::fmt::{FormatFn, Formatter};
use crate::writer::{self, Writer};

/// The default name for the environment variable to read filters from.
pub const DEFAULT_FILTER_ENV: &str = "RUST_LOG";
Expand Down
28 changes: 14 additions & 14 deletions src/fmt/writer/buffer.rs → src/writer/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{io, sync::Mutex};

use crate::fmt::writer::WriteStyle;
use crate::writer::WriteStyle;

#[derive(Debug)]
pub(in crate::fmt::writer) struct BufferWriter {
pub(crate) struct BufferWriter {
target: WritableTarget,
write_style: WriteStyle,
}

impl BufferWriter {
pub(in crate::fmt::writer) fn stderr(is_test: bool, write_style: WriteStyle) -> Self {
pub(crate) fn stderr(is_test: bool, write_style: WriteStyle) -> Self {
BufferWriter {
target: if is_test {
WritableTarget::PrintStderr
Expand All @@ -20,7 +20,7 @@ impl BufferWriter {
}
}

pub(in crate::fmt::writer) fn stdout(is_test: bool, write_style: WriteStyle) -> Self {
pub(crate) fn stdout(is_test: bool, write_style: WriteStyle) -> Self {
BufferWriter {
target: if is_test {
WritableTarget::PrintStdout
Expand All @@ -31,7 +31,7 @@ impl BufferWriter {
}
}

pub(in crate::fmt::writer) fn pipe(
pub(crate) fn pipe(
pipe: Box<Mutex<dyn io::Write + Send + 'static>>,
write_style: WriteStyle,
) -> Self {
Expand All @@ -41,15 +41,15 @@ impl BufferWriter {
}
}

pub(in crate::fmt::writer) fn write_style(&self) -> WriteStyle {
pub(crate) fn write_style(&self) -> WriteStyle {
self.write_style
}

pub(in crate::fmt::writer) fn buffer(&self) -> Buffer {
pub(crate) fn buffer(&self) -> Buffer {
Buffer(Vec::new())
}

pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> {
pub(crate) fn print(&self, buf: &Buffer) -> io::Result<()> {
#![allow(clippy::print_stdout)] // enabled for tests only
#![allow(clippy::print_stderr)] // enabled for tests only

Expand Down Expand Up @@ -115,23 +115,23 @@ fn adapt(buf: &[u8], write_style: WriteStyle) -> io::Result<Vec<u8>> {
Ok(adapted)
}

pub(in crate::fmt) struct Buffer(Vec<u8>);
pub(crate) struct Buffer(Vec<u8>);

impl Buffer {
pub(in crate::fmt) fn clear(&mut self) {
pub(crate) fn clear(&mut self) {
self.0.clear();
}

pub(in crate::fmt) fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
pub(crate) fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.extend(buf);
Ok(buf.len())
}

pub(in crate::fmt) fn flush(&mut self) -> io::Result<()> {
pub(crate) fn flush(&mut self) -> io::Result<()> {
Ok(())
}

pub(in crate::fmt) fn as_bytes(&self) -> &[u8] {
pub(crate) fn as_bytes(&self) -> &[u8] {
&self.0
}
}
Expand All @@ -145,7 +145,7 @@ impl std::fmt::Debug for Buffer {
/// Log target, either `stdout`, `stderr` or a custom pipe.
///
/// Same as `Target`, except the pipe is wrapped in a mutex for interior mutability.
pub(super) enum WritableTarget {
pub(crate) enum WritableTarget {
/// Logs will be written to standard output.
WriteStdout,
/// Logs will be printed to standard output.
Expand Down
9 changes: 5 additions & 4 deletions src/fmt/writer/mod.rs → src/writer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
mod buffer;
mod target;

use self::buffer::BufferWriter;
use std::{io, mem, sync::Mutex};

pub(super) use self::buffer::Buffer;
use buffer::BufferWriter;

pub(crate) use buffer::Buffer;

pub use target::Target;

Expand Down Expand Up @@ -55,11 +56,11 @@ impl Writer {
self.inner.write_style()
}

pub(super) fn buffer(&self) -> Buffer {
pub(crate) fn buffer(&self) -> Buffer {
self.inner.buffer()
}

pub(super) fn print(&self, buf: &Buffer) -> io::Result<()> {
pub(crate) fn print(&self, buf: &Buffer) -> io::Result<()> {
self.inner.print(buf)
}
}
Expand Down
File renamed without changes.
Loading