aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2022-11-28 13:13:56 -0500
committerNathan Perry <np@nathanperry.dev>2022-11-28 13:13:56 -0500
commit14a9ad0c85b0ee6f190323a8903d1239b8968d22 (patch)
treef2747f9814ea12081f4850a8970e6d800ece3902 /src
parent22cdf56ffccaefd0c9a4cb67cac87c7620d2d3f3 (diff)
nix: write nixos test configuration
- filter rust sources to avoid spurious rebuilds - fix accidental circular reference in nix flake - fix postgres startup scripts and behavior - thulani logger doesn't log to file by default
Diffstat (limited to 'src')
-rw-r--r--src/db/mod.rs1
-rw-r--r--src/log_setup.rs42
-rw-r--r--src/main.rs2
3 files changed, 26 insertions, 19 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 483665e..476d9d9 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -54,6 +54,7 @@ pub fn connection() -> Result<PgConnection> {
MIGRATE.call_once(|| {
log::info!("running migrations");
conn.run_pending_migrations(MIGRATIONS).expect("failed running migrations");
+ log::info!("migrations complete");
});
conn
diff --git a/src/log_setup.rs b/src/log_setup.rs
index a51ebcc..c01f3f5 100644
--- a/src/log_setup.rs
+++ b/src/log_setup.rs
@@ -2,13 +2,13 @@ use crate::{Result, Error};
use fern::colors::{Color, ColoredLevelConfig};
-pub fn init() -> Result<()> {
+pub fn init(file_output: bool) -> Result<()> {
let colors = ColoredLevelConfig::new()
.info(Color::Green)
.debug(Color::BrightBlue)
.trace(Color::BrightMagenta);
- fern::Dispatch::new()
+ let mut logger = fern::Dispatch::new()
.level_for("serenity::voice::connection", log::LevelFilter::Error)
.chain(fern::Dispatch::new()
.format(move |out, message, record| {
@@ -23,21 +23,27 @@ pub fn init() -> Result<()> {
.level(log::LevelFilter::Warn)
.level_for("thulani", log::LevelFilter::Debug)
.chain(std::io::stdout())
- )
- .chain(fern::Dispatch::new()
- .format(|out, message, record| {
- out.finish(format_args!(
- "{} [{}] [{}] {}",
- chrono::Local::now().format("%_m/%_d/%y %l:%M:%S%P"),
- record.level(),
- record.target(),
- message
- ))
- })
- .level(log::LevelFilter::Info)
- .level_for("thulani", log::LevelFilter::Trace)
- .chain(fern::log_file("thulani.log").expect("problem creating log file"))
- )
+ );
+
+ if file_output {
+ logger = logger
+ .chain(fern::Dispatch::new()
+ .format(|out, message, record| {
+ out.finish(format_args!(
+ "{} [{}] [{}] {}",
+ chrono::Local::now().format("%_m/%_d/%y %l:%M:%S%P"),
+ record.level(),
+ record.target(),
+ message
+ ))
+ })
+ .level(log::LevelFilter::Info)
+ .level_for("thulani", log::LevelFilter::Trace)
+ .chain(fern::log_file("thulani.log").expect("problem creating log file"))
+ );
+ }
+
+ logger
.apply()
.map_err(Error::from)
-} \ No newline at end of file
+}
diff --git a/src/main.rs b/src/main.rs
index ffcd2f5..1bf3e98 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -59,7 +59,7 @@ const BACKOFF_INIT: f64 = 100.0;
const MIN_RUN_DURATION: Duration = Duration::from_secs(120);
fn main() {
- log_setup::init().expect("initializing logging");
+ log_setup::init(false).expect("initializing logging");
let mut backoff_count: usize = 0;