Skip to main content

logged_stream/
lib.rs

1//! This library provides a [`LoggedStream`] structure which can be used as a wrapper for
2//! underlying IO object which implements [`Write`] and [`Read`] traits or their
3//! asynchronous analogues from [`tokio`] library to enable logging of all read and write
4//! operations, errors and drop.
5//!
6//! [`LoggedStream`] structure constructs from four parts:
7//!
8//! -   Underlying IO object, which must implement [`Write`] and [`Read`] traits or their
9//!     asynchronous analogues from [`tokio`] library: [`AsyncRead`] and [`AsyncWrite`].
10//! -   Buffer formatting part, which must implement [`BufferFormatter`] trait provided by
11//!     this library. This part of [`LoggedStream`] is responsible for the form you will see the
12//!     input and output bytes. Currently this library provides the following implementations of
13//!     [`BufferFormatter`] trait: [`UppercaseHexadecimalFormatter`], [`LowercaseHexadecimalFormatter`],
14//!     [`DecimalFormatter`], [`BinaryFormatter`] and [`OctalFormatter`]. Also [`BufferFormatter`] is
15//!     public trait so you are free to construct your own implementation.
16//! -   Filtering part, which must implement [`RecordFilter`] trait provided by this library.
17//!     This part of [`LoggedStream`] is responsible for log records filtering. Currently this
18//!     library provides the following implementations of [`RecordFilter`] trait: [`DefaultFilter`] which
19//!     accepts all log records, [`RecordKindFilter`] which accepts logs with kinds specified during
20//!     construct, [`AllFilter`] which combines multiple filters with AND logic (accepts record only if
21//!     all underlying filters accept it), and [`AnyFilter`] which combines multiple filters with OR logic
22//!     (accepts record if any underlying filter accepts it). Also [`RecordFilter`] is public trait and
23//!     you are free to construct your own implementation.
24//! -   Logging part, which must implement [`Logger`] trait provided by this library. This part
25//!     of [`LoggedStream`] is responsible for further work with constructed, formatter and filtered
26//!     log record. For example, it can be outputted to console, written to the file, written to database,
27//!     written to the memory for further use or sended by the channel. Currently this library provides
28//!     the following implementations of [`Logger`] trait: [`ConsoleLogger`], [`MemoryStorageLogger`],
29//!     [`ChannelLogger`] and [`FileLogger`]. Also [`Logger`] is public trait and you are free to construct
30//!     your own implementation.
31//!
32//! [`Write`]: std::io::Write
33//! [`Read`]: std::io::Read
34//! [`AsyncRead`]: tokio::io::AsyncRead
35//! [`AsyncWrite`]: tokio::io::AsyncWrite
36
37mod buffer_formatter;
38mod filter;
39mod logger;
40mod record;
41mod stream;
42
43pub use buffer_formatter::BinaryFormatter;
44pub use buffer_formatter::BufferFormatter;
45pub use buffer_formatter::DecimalFormatter;
46pub use buffer_formatter::LowercaseHexadecimalFormatter;
47pub use buffer_formatter::OctalFormatter;
48pub use buffer_formatter::UppercaseHexadecimalFormatter;
49pub use filter::AllFilter;
50pub use filter::AnyFilter;
51pub use filter::DefaultFilter;
52pub use filter::RecordFilter;
53pub use filter::RecordKindFilter;
54pub use logger::ChannelLogger;
55pub use logger::ConsoleLogger;
56pub use logger::FileLogger;
57pub use logger::Logger;
58pub use logger::MemoryStorageLogger;
59pub use record::Record;
60pub use record::RecordKind;
61pub use stream::LoggedStream;