Skip to content

A Rust logger that stores entries in memory, allowing late and sporadic consumption.

License

Notifications You must be signed in to change notification settings

gahag/memory_logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memory Logger

A logger that stores entries in memory, allowing late and sporadic consumption.

Cargo Documentation

Features

  • Two flavors: blocking and asynchronous.
  • Optional target matching using Regex.
  • Simple design, few dependencies, very fast to compile.
  • No unsafe code.

Blocking

Both logging and reading use a mutex around a single buffer, and therefore may block. This should be good enough for most scenarios, and has a smaller memory overhead and better locality (single buffer).

use regex::Regex;

use memory_logger::blocking::MemoryLogger;


fn main() -> Result<(), Box<dyn std::error::Error>> {
	let target = Regex::new("^mycrate::my_module")?; // optional
	let logger = MemoryLogger::setup(log::Level::Info, target)?;

	log::info!("This is a info.");
	log::warn!("This is a warning.");

	let contents = logger.read();

	assert!(contents.contains("This is a info."));
	assert!(contents.contains("This is a warning."));
	Ok(())
}

Asynchronous

Both logging and reading use a channel, and may never block. This should be faster for high contention scenarios, but has a higher memory overhead and worse locality.

use regex::Regex;

use memory_logger::asynchronous::MemoryLogger;


fn main() -> Result<(), Box<dyn std::error::Error>> {
	let target = Regex::new("^mycrate::my_module")?; // optional
	let logger = MemoryLogger::setup(log::Level::Info, target)?;

	log::info!("This is a info.");
	log::warn!("This is a warning.");

	let mut reader = logger.read();

	assert!(reader.next().unwrap().contains("This is a info."));
	assert!(reader.next().unwrap().contains("This is a warning."));
	Ok(())
}

Simplicity

Memory logger aims to be a simple logging mechanism. There are no plans to implement advanced features.

Licence

memory_logger is licenced under the MIT Licence.

About

A Rust logger that stores entries in memory, allowing late and sporadic consumption.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages