Write logger

This commit is contained in:
Alex D. 2024-11-04 15:09:41 +00:00
parent 6a32f160b7
commit 6cfa4c357e
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
38 changed files with 76 additions and 0 deletions

7
logger/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "logger"
version = "0.1.0"

6
logger/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "logger"
version = "0.1.0"
edition = "2021"
[dependencies]

34
logger/src/main.rs Normal file
View File

@ -0,0 +1,34 @@
pub trait Logger {
/// Log a message at the given verbosity level.
fn log(&self, verbosity: u8, message: &str);
}
struct StdoutLogger;
impl Logger for StdoutLogger {
fn log(&self, verbosity: u8, message: &str) {
println!("verbosity={verbosity}: {message}");
}
}
struct VerbosityFilter {
max_verbosity: u8,
inner: StdoutLogger,
}
impl Logger for VerbosityFilter {
fn log(&self, verbosity: u8, message: &str) {
if verbosity <= self.max_verbosity {
self.inner.log(verbosity, message)
}
}
}
fn main() {
let logger = VerbosityFilter {
max_verbosity: 3,
inner: StdoutLogger,
};
logger.log(5, "FYI");
logger.log(2, "Uhoh");
}

View File

@ -0,0 +1 @@
{"rustc_fingerprint":6732347950899328623,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.78.0 (9b00956e5 2024-04-29) (Alpine Linux 1.78.0-r0)\nbinary: rustc\ncommit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6\ncommit-date: 2024-04-29\nhost: x86_64-alpine-linux-musl\nrelease: 1.78.0\nLLVM version: 17.0.6\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/usr\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"musl\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"alpine\"\nunix\n","stderr":""}},"successes":{}}

View File

@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/

View File

View File

@ -0,0 +1 @@
e93c6c14f8990fed

View File

@ -0,0 +1 @@
{"rustc":527819051023801553,"features":"[]","declared_features":"","target":16938823611516788830,"profile":11597332650809196192,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/logger-24dda9cfa85dde2e/dep-bin-logger"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

View File

@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@ -0,0 +1 @@
c1fb9f4ae6f812af

View File

@ -0,0 +1 @@
{"rustc":527819051023801553,"features":"[]","declared_features":"","target":16938823611516788830,"profile":11983525691607113661,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/logger-25d7fa76bb1e13bd/dep-test-bin-logger"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

View File

@ -0,0 +1 @@
f8f84ecbc97cbdac

View File

@ -0,0 +1 @@
{"rustc":527819051023801553,"features":"[]","declared_features":"","target":16938823611516788830,"profile":5601947868832436996,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/logger-93bf7dd47194b21e/dep-bin-logger"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

View File

@ -0,0 +1 @@
This file has an mtime of when this was started.

Binary file not shown.

View File

@ -0,0 +1,5 @@
/home/caskd/Sources/Repositories/Personal/Rust/logger/target/debug/deps/logger-24dda9cfa85dde2e: src/main.rs
/home/caskd/Sources/Repositories/Personal/Rust/logger/target/debug/deps/logger-24dda9cfa85dde2e.d: src/main.rs
src/main.rs:

View File

@ -0,0 +1,5 @@
/home/caskd/Sources/Repositories/Personal/Rust/logger/target/debug/deps/liblogger-25d7fa76bb1e13bd.rmeta: src/main.rs
/home/caskd/Sources/Repositories/Personal/Rust/logger/target/debug/deps/logger-25d7fa76bb1e13bd.d: src/main.rs
src/main.rs:

View File

@ -0,0 +1,5 @@
/home/caskd/Sources/Repositories/Personal/Rust/logger/target/debug/deps/liblogger-93bf7dd47194b21e.rmeta: src/main.rs
/home/caskd/Sources/Repositories/Personal/Rust/logger/target/debug/deps/logger-93bf7dd47194b21e.d: src/main.rs
src/main.rs:

BIN
logger/target/debug/logger Executable file

Binary file not shown.

View File

@ -0,0 +1 @@
/home/caskd/Sources/Repositories/Personal/Rust/logger/target/debug/logger: /home/caskd/Sources/Repositories/Personal/Rust/logger/src/main.rs