Crate logged_stream
source ·Expand description
This library provides a LoggedStream
structure which can be used as a wrapper for
underlying IO object which implements Write
and Read
traits or their
asynchronous analogues from tokio
library to enable logging of all read and write
operations, errors and drop.
LoggedStream
structure constructs from four parts:
- Underlying IO object, which must implement
Write
andRead
traits or their asynchronous analogues fromtokio
library:AsyncRead
andAsyncWrite
. - Buffer formatting part, which must implement
BufferFormatter
trait provided by this library. This part ofLoggedStream
is responsible for the form you will see the input and output bytes. Currently this library provides the following implementations ofBufferFormatter
trait:UppercaseHexadecimalFormatter
,LowercaseHexadecimalFormatter
,DecimalFormatter
,BinaryFormatter
andOctalFormatter
. AlsoBufferFormatter
is public trait so you are free to construct your own implementation. - Filtering part, which must implement
RecordFilter
trait provide by this library. This part ofLoggedStream
is responsible for log records filtering. Currently this library provides the following implementation ofRecordFilter
trait:DefaultFilter
which accepts all log records andRecordKindFilter
which accepts logs with kinds specified during construct. AlsoRecordFilter
is public trait and you are free to construct your own implementation. - Logging part, which must implement
Logger
trait provided by this library. This part ofLoggedStream
is responsible for further work with constructed, formatter and filtered log record. For example, it can be outputted to console, written to the file, written to database, written to the memory for further use or sended by the channel. Currently this library provides the following implementations ofLogger
trait:ConsoleLogger
,MemoryStorageLogger
andChannelLogger
. AlsoLogger
is public trait and you are free to construct you own implementation.
Structs§
- This implementation of
BufferFormatter
trait formats provided bytes buffer in binary number system. - This implementation of
Logger
trait sends log records (Record
) by the sending-half of underlying asynchronous channel. You are able to take receiving-half usingtake_receiver
andtake_receiver_unchecked
methods. - This implementation of
Logger
trait writes log record (Record
) into console using providedlog::Level
. Log records withError
kind ignore providedlog::Level
and always write withlog::Level::Error
. - This implementation of
BufferFormatter
trait formats provided bytes buffer in decimal number system. - This is default implementation of
RecordFilter
trait whichcheck
method always returntrue
. It should be constructed usingDefault::default
method. - This is a structure that can be used as a wrapper for underlying IO object which implements
Read
andWrite
traits or their asynchronous analogues fromtokio
libraryAsyncRead
andAsyncWrite
to enable logging of all read and write operations, errors and drop. - This implementation of
BufferFormatter
trait formats provided bytes buffer in hexdecimal number system. - This implementation of
Logger
trait writes log record (Record
) into inner collection (collections::VecDeque
). Inner collection length limited by number provided during structure construction. You are able to retrieve accumulated log records from inner collection usingget_log_records
method and clean inner collection usingclear_log_records
method. - This implementation of
BufferFormatter
trait formats provided bytes buffer in octal number system. - This structure represents a log record and contains message string, creation timestamp (
DateTime
<Utc
>) and record kind (RecordKind
). - This implementation of
RecordFilter
trait accepts allowed log record kinds (RecordKind
) array during construction and itscheck
method returnstrue
if received log record kind presented inside this array. - This implementation of
BufferFormatter
trait formats provided bytes buffer in hexadecimal number system.
Enums§
- This enumeration represents log record kind. It is contained inside
Record
and helps to determine how to work with log record message content which is different for each log record kind.
Traits§
- This trait allows to format bytes buffer using
format_buffer
method. It should be implemented for structures which are going to be used as formatting part insideLoggedStream
. - This trait allows to process log record (
Record
) usinglog
method. It should be implemented for structures which are going to be used as logging part insideLoggedStream
. Methodlog
is called byLoggedStream
for further log record processing (writing to the console, to the memory or database, etc.) after log record message was formatted by some implementation ofBufferFormatter
and the entire log record was filtered by some implementation ofRecordFilter
. - This trait allows to filter log records (
Record
) usingcheck
method which returnsbool
value. It should be implemented for structures which are going to be used as filtering part insideLoggedStream
.