aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/add-student-x500s.rs14
-rw-r--r--src/bin/lambo.rs14
-rw-r--r--src/lib.rs19
3 files changed, 21 insertions, 26 deletions
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(())
+}