aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-01-16 03:02:48 -0600
committerNathan Ringo <nathan@remexre.com>2024-01-16 03:02:48 -0600
commitaf0d1d5cb4d9ddb1a69ba5e8313d593d02960c88 (patch)
treef9fe1b38c6aa171177465952b1f3a6a12550dc76
parentbc91cdbc75b299a810da0fed2c09acf040620fbe (diff)
Change logging implementation.
-rw-r--r--Cargo.lock80
-rw-r--r--Cargo.toml2
-rw-r--r--src/bin/add-student-x500s.rs14
-rw-r--r--src/bin/lambo.rs14
-rw-r--r--src/lib.rs19
5 files changed, 46 insertions, 83 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 45ef8cb..29f71a5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -148,17 +148,6 @@ dependencies = [
]
[[package]]
-name = "atty"
-version = "0.2.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
-dependencies = [
- "hermit-abi 0.1.19",
- "libc",
- "winapi",
-]
-
-[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -293,10 +282,8 @@ checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [
"android-tzdata",
"iana-time-zone",
- "js-sys",
"num-traits",
"serde",
- "wasm-bindgen",
"windows-targets 0.48.5",
]
@@ -347,6 +334,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
+name = "colored"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
+dependencies = [
+ "lazy_static",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
name = "command_attr"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -825,15 +822,6 @@ dependencies = [
[[package]]
name = "hermit-abi"
-version = "0.1.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
-dependencies = [
- "libc",
-]
-
-[[package]]
-name = "hermit-abi"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
@@ -1027,8 +1015,8 @@ dependencies = [
"log",
"serde",
"serenity",
+ "simple_logger",
"sqlx",
- "stderrlog",
"time",
"tokio",
"toml",
@@ -1242,7 +1230,7 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
- "hermit-abi 0.3.3",
+ "hermit-abi",
"libc",
]
@@ -1731,6 +1719,18 @@ dependencies = [
]
[[package]]
+name = "simple_logger"
+version = "4.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e7e46c8c90251d47d08b28b8a419ffb4aede0f87c2eea95e17d1d5bacbf3ef1"
+dependencies = [
+ "colored",
+ "log",
+ "time",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
name = "skeptic"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2014,19 +2014,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
-name = "stderrlog"
-version = "0.5.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "69a26bbf6de627d389164afa9783739b56746c6c72c4ed16539f4ff54170327b"
-dependencies = [
- "atty",
- "chrono",
- "log",
- "termcolor",
- "thread_local",
-]
-
-[[package]]
name = "stringprep"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2112,15 +2099,6 @@ dependencies = [
]
[[package]]
-name = "termcolor"
-version = "1.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
-dependencies = [
- "winapi-util",
-]
-
-[[package]]
name = "thiserror"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2141,16 +2119,6 @@ dependencies = [
]
[[package]]
-name = "thread_local"
-version = "1.1.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
-dependencies = [
- "cfg-if",
- "once_cell",
-]
-
-[[package]]
name = "time"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index aa4f328..57825b2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,8 +11,8 @@ futures = "0.3.30"
log = "0.4.20"
serde = { version = "1.0.195", features = ["derive"] }
serenity = "0.12.0"
+simple_logger = "4.3.3"
sqlx = { version = "0.7.3", features = ["runtime-tokio", "sqlite", "time"] }
-stderrlog = "0.5.4"
time = { version = "0.3.31", features = ["local-offset"] }
tokio = { version = "1.35.1", features = ["rt-multi-thread"] }
toml = "0.8.8"
diff --git a/src/bin/add-student-x500s.rs b/src/bin/add-student-x500s.rs
index d39568c..ddf2404 100644
--- a/src/bin/add-student-x500s.rs
+++ b/src/bin/add-student-x500s.rs
@@ -4,7 +4,6 @@ use futures::{stream, FutureExt, StreamExt};
use lambo::config::Config;
use sqlx::sqlite::SqlitePoolOptions;
use std::{fs, path::PathBuf};
-use stderrlog::StdErrLog;
#[derive(Debug, Parser)]
struct Args {
@@ -41,18 +40,7 @@ async fn main() -> Result<()> {
let args = Args::parse();
// Set up logging.
- {
- let mut logger = StdErrLog::new();
- match args.quiet {
- 0 => logger.verbosity(1 + args.verbose as usize),
- 1 => logger.verbosity(0),
- 2 => logger.quiet(true),
- // UNREACHABLE: A maximum of two occurrences of quiet are allowed.
- _ => unreachable!(),
- };
- // UNWRAP: No other logger should be set up.
- logger.show_module_names(true).init().unwrap()
- }
+ lambo::configure_logger(args.quiet, args.verbose)?;
// Parse the config file.
let config = Config::read_from_file(&args.config_path)?;
diff --git a/src/bin/lambo.rs b/src/bin/lambo.rs
index 1134480..f446308 100644
--- a/src/bin/lambo.rs
+++ b/src/bin/lambo.rs
@@ -4,7 +4,6 @@ use lambo::{config::Config, handlers::*};
use serenity::{all::GatewayIntents, Client};
use sqlx::sqlite::SqlitePoolOptions;
use std::{path::PathBuf, sync::Arc};
-use stderrlog::StdErrLog;
#[derive(Debug, Parser)]
struct Args {
@@ -38,18 +37,7 @@ async fn main() -> Result<()> {
let args = Args::parse();
// Set up logging.
- {
- let mut logger = StdErrLog::new();
- match args.quiet {
- 0 => logger.verbosity(1 + args.verbose as usize),
- 1 => logger.verbosity(0),
- 2 => logger.quiet(true),
- // UNREACHABLE: A maximum of two occurrences of quiet are allowed.
- _ => unreachable!(),
- };
- // UNWRAP: No other logger should be set up.
- logger.show_module_names(true).init().unwrap()
- }
+ lambo::configure_logger(args.quiet, args.verbose)?;
// Parse the config file.
let config = Config::read_from_file(&args.config_path)?;
diff --git a/src/lib.rs b/src/lib.rs
index 61d095d..8344c09 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,2 +1,21 @@
pub mod config;
pub mod handlers;
+
+use anyhow::{Context, Result};
+
+pub fn configure_logger(quiet: u8, verbose: u8) -> Result<()> {
+ let level = match (quiet, verbose) {
+ (0, 0) => Some(log::Level::Warn),
+ (0, 1) => Some(log::Level::Info),
+ (0, 2) => Some(log::Level::Debug),
+ (0, _) => Some(log::Level::Trace),
+ (1, _) => Some(log::Level::Error),
+ (_, _) => None,
+ };
+
+ if let Some(level) = level {
+ simple_logger::init_with_level(level).context("failed to configure logger")?;
+ }
+
+ Ok(())
+}