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 provide by this library.
17//! This part of [`LoggedStream`] is responsible for log records filtering. Currently this
18//! library provides the following implementation of [`RecordFilter`] trait: [`DefaultFilter`] which
19//! accepts all log records and [`RecordKindFilter`] which accepts logs with kinds specified during
20//! construct. Also [`RecordFilter`] is public trait and you are free to construct your own implementation.
21//! - Logging part, which must implement [`Logger`] trait provided by this library. This part
22//! of [`LoggedStream`] is responsible for further work with constructed, formatter and filtered
23//! log record. For example, it can be outputted to console, written to the file, written to database,
24//! written to the memory for further use or sended by the channel. Currently this library provides
25//! the following implementations of [`Logger`] trait: [`ConsoleLogger`], [`MemoryStorageLogger`],
26//! [`ChannelLogger`] and [`FileLogger`]. Also [`Logger`] is public trait and you are free to construct
27//! your own implementation.
28//!
29//! [`Write`]: std::io::Write
30//! [`Read`]: std::io::Read
31//! [`AsyncRead`]: tokio::io::AsyncRead
32//! [`AsyncWrite`]: tokio::io::AsyncWrite
33
34mod buffer_formatter;
35mod filter;
36mod logger;
37mod record;
38mod stream;
39
40pub use buffer_formatter::BinaryFormatter;
41pub use buffer_formatter::BufferFormatter;
42pub use buffer_formatter::DecimalFormatter;
43pub use buffer_formatter::LowercaseHexadecimalFormatter;
44pub use buffer_formatter::OctalFormatter;
45pub use buffer_formatter::UppercaseHexadecimalFormatter;
46pub use filter::DefaultFilter;
47pub use filter::RecordFilter;
48pub use filter::RecordKindFilter;
49pub use logger::ChannelLogger;
50pub use logger::ConsoleLogger;
51pub use logger::FileLogger;
52pub use logger::Logger;
53pub use logger::MemoryStorageLogger;
54pub use record::Record;
55pub use record::RecordKind;
56pub use stream::LoggedStream;