Task-based logging for rust

Related tags

Logging task_log
Overview

task_log

build test lint docs.rs Crates.io

task_log is a task-based logger.

Installing

Just add task_log = 0.1.4 to your Cargo.toml's dependency section.

Example

Let's get right to the chase. What does using this logger look like?

Result<()> { let filename = "hello.txt"; fs::write(filename, "foo bar")?; thread::sleep(Duration::from_secs(2)); fs::remove_file(filename)?; Ok(()) }) .expect("Failed to create and delete the file"); } ">
use std::io::Result;
use std::time::Duration;
use std::{fs, thread};

use task_log::task;

fn main() {
	task("Creating and removing file", || -> Result<()> {
		let filename = "hello.txt";
		fs::write(filename, "foo bar")?;
		thread::sleep(Duration::from_secs(2));
		fs::remove_file(filename)?;
		Ok(())
	})
	.expect("Failed to create and delete the file");
}

As you can see we provide a task to run and a description of what that task is doing. When we run this code we get the following output.

demo

To see more examples see the examples folder.

Configuration

You can configure task_log's task function using a struct called ConfigBuilder. Here is an example of using ConfigBuilder:

u32 { let result = 1 + 2; thread::sleep(Duration::from_secs(2)); result }); println!("Sum is {}", sum) }">
use std::thread;
use std::time::Duration;

use task_log::{task, ConfigBuilder};

fn main() {
	ConfigBuilder::new()
		.duration(false)
		.apply()
		.expect("Failed to setup configuration");

	let sum = task("Adding 1 and 2", || -> u32 {
		let result = 1 + 2;
		thread::sleep(Duration::from_secs(2));
		result
	});

	println!("Sum is {}", sum)
}

To learn more about ConfigBuilder please reference the docs.rs documentation.

Future Plans

Here are some features I'm hoping to implement in the future:

  • Run time: Output the run time so far in the RUNNING prefix.
  • Spinners: Show a loading symbol for long-running tasks.
  • File output: Allow writing of logs to a file.
  • Double log lines: Option to output log to a second line instead of replacing the first one.
You might also like...
A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice
A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice

sensible-env-logger A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice. This is a thin wrapper around pret

A rust library for creating and managing logs of arbitrary binary data

A rust library for creating and managing logs of arbitrary binary data. Presently it's used to collect sensor data. But it should generally be helpful in cases where you need to store timeseries data, in a nearly (but not strictly) append-only fashion.

A cool log library built using rust-lang

RustLog A cool log library built using rust-lang Installation: Cargo.toml rustlog = { git = "https://github.com/krishpranav/rustlog" } log = "0.4.17"

Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

TimeKnight is a neat little TUI-based timer app I use in conjunction with a task tracker
TimeKnight is a neat little TUI-based timer app I use in conjunction with a task tracker

TimeKnight is a neat little TUI-based timer app I use in conjunction with a task tracker. It's kind of a secret sauce for productivity (particularly if you have ADHD or have a ridiculously overactive brain).

A terminal-based daily task management tool with minimal overhead
A terminal-based daily task management tool with minimal overhead

Arenta A terminal-based daily task management tool with minimal overhead. Demo Features Complete CRUD support of daily tasks with intuitive syntax Vis

Simple, thread-safe, counter based progress logging

🦫 proglog Documentation Crates.io This is a simple, thread-safe, count-based, progress logger. Synopsis proglog hooks into your existing log implemen

Task runner and process manager for Rust
Task runner and process manager for Rust

Steward Task runner and process manager for Rust. If you're not happy managing your infrastructure with a pile of bash scripts, this crate might be he

delicate A lightweight and distributed task scheduling platform written in rust
delicate A lightweight and distributed task scheduling platform written in rust

A lightweight and distributed task scheduling platform written in rust.

Rust library to ease the task of creating daemons

Rust library to ease the task of creating daemons

Rust task runner and build tool.

cargo-make Rust task runner and build tool. Overview Installation Binary Release Usage Simple Example Tasks, Dependencies and Aliases Commands, Script

Background task processing for Rust applications with Tokio, Diesel, and PostgreSQL.
Background task processing for Rust applications with Tokio, Diesel, and PostgreSQL.

Async persistent background task processing for Rust applications with Tokio. Queue asynchronous tasks to be processed by workers. It's designed to be

CrustAGI is an Task-driven Autonomous Agent experiment written in Rust

CrustAGI 🦀 CrustAGI is an experimental Rust-based implementation of an AI-powered task management system that uses OpenAI and Pinecone APIs to create

A simple, efficient Rust library for handling asynchronous job processing and task queuing.

job_queue Setup cargo add job_queue Usage Create a job use job_queue::{Error, Job, typetag, async_trait, serde}; #[derive(Debug, serde::Deserialize,

🎭 A CLI task runner defined by a simple markdown file
🎭 A CLI task runner defined by a simple markdown file

mask is a CLI task runner which is defined by a simple markdown file. It searches for a maskfile.md in the current directory which it then parses for

Task scheduler for the Internet Computer

IC Cron Makes your IC canister proactive Abstract Canisters are reactive by their nature - they only do something when they're asked by a client or an

Cronos - a decentralized task scheduler for Solana

Cronos Cronos is a decentralized task scheduler for Solana. Packages Package Description Version Docs cronos-bot Cronos bot to execute tasks GitBook c

Very simple, efficient, task oriented, low cognitive, Midi player and jukebox for midi instruments
Very simple, efficient, task oriented, low cognitive, Midi player and jukebox for midi instruments

Midi and Virtual Book jukebox Player A cross-platform MIDI and virtual book jukebox player. It only includes the necessary functionalities to play MID

Local-first task manager/bug tracker that stores everything right in the git repository and can sync issues from/to GitHub.
Local-first task manager/bug tracker that stores everything right in the git repository and can sync issues from/to GitHub.

git-task Local-first task manager/bug tracker within your git repository which can import issues from GitHub. Installation Build a binary, then add it

Comments
  • Time formatting issues

    Time formatting issues

    When working in a time format that can go over 100 (such as nanoseconds) the formatting doesn't work correctly. This should be fixed by using proper padding supplied by rust's formatting.

    bug good first issue 
    opened by gleich 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    opened by imgbot[bot] 0
Owner
Matt Gleich
makin' stuff
Matt Gleich
Structured, contextual, extensible, composable logging for Rust

Getting started Introduction FAQ Crate list slog-rs - The Logging for Rust Introduction (please read) slog is an ecosystem of reusable components for

slog-rs 1.4k Jan 3, 2023
A highly configurable logging framework for Rust

log4rs log4rs is a highly configurable logging framework modeled after Java's Logback and log4j libraries. Warning If you are using the file rotation

null 753 Jan 8, 2023
💬 A couple of functions to make logging in Rust easier.

Rust logging ⛔ ?? A couple of functions to make logging in Rust easier. Installation ?? Just add the code of code.rs to your project. You can copy/pas

Skwal 2 Apr 7, 2022
A logging library for eBPF programs.

aya-log - a logging library for eBPF programs Overview aya-log is a logging library for eBPF programs written using aya. Think of it as the log crate

null 18 Oct 13, 2022
defmt is a highly efficient logging framework that targets resource-constrained devices, like microcontrollers

defmt defmt ("de format", short for "deferred formatting") is a highly efficient logging framework that targets resource-constrained devices, like mic

Knurling 476 Jan 2, 2023
A pretty, easy-to-use logger for Rust.

pretty-env-logger A simple logger built on top of env_logger. It is configured via an environment variable and writes to standard error with nice colo

Sean McArthur 390 Dec 29, 2022
Application level tracing for Rust.

Website | Chat | Documentation (master branch) Overview tracing is a framework for instrumenting Rust programs to collect structured, event-based diag

Tokio 3.3k Jan 3, 2023
A Rust logger with various features.

Moe Logger (>ω<) Another logger based on pretty-env-logger and env_logger. Allow writing log to file with features like formatting, file rotation. Usa

Rui Li 4 Sep 24, 2021
godot-logger is an easy-to-use logger for godot-rust projects.

godot-logger is an easy-to-use logger for godot-rust projects. It prints logs to Godot's output console and supports module-specific log levels.

Jan David 10 Nov 17, 2022
Another Key Logger Yet. Rust.

Another Key Logger Yet. Rust. For my very first experience of working with Rust, I decided to manage the keyboard, this time by logging and writing th

(Not) Kearash 0 May 3, 2022