Skip to content

Commit

Permalink
Enable log for other dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Oct 27, 2023
1 parent fe6528d commit 52368f9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ custom_settings.toml
DB
.vscode
.idea
.helix

# Logs
logs
Expand Down
75 changes: 46 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ axum-login = "0.6.0"
axum-sessions = "0.5.0"
chrono = { version = "0.4.26", features = ["serde", "alloc", "clock"], default-features = false }
chrono-tz = { version = "0.8.3", features = ["serde"] }
clap = { version = "4.3.12", features = ["derive"] }
clap = { version = "4.4.7", features = ["derive"] }
comrak = "0.18.0"
config = { version = "0.13.3", default-features = false, features = ["indexmap", "toml"] }
djangohashers = { version = "1.6.7", default-features = false, features = ["with_argon2"] }
Expand Down Expand Up @@ -53,7 +53,7 @@ str-macro = "1.0.0"
strum = { version = "0.25.0", features = ["derive", "strum_macros"] }
strum_macros = "0.25.0"
syntect = { version = "5.0.0", default-features = false, features = ["fancy-regex", "html"] }
thiserror = "1.0.43"
thiserror = "1.0.50"
tokio = { version = "1.29.1", features = ["full"] }
tower-http = { version = "0.4.1", features = ["trace"] }
tracing = { git = "https://github.com/hongquan/tracing.git", branch = "feat/tracing-journald" }
Expand Down
23 changes: 12 additions & 11 deletions src/thingsup.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
use std::net::{AddrParseError, SocketAddr};
use std::{env, io};
use std::net::{SocketAddr, AddrParseError};

use clap::Parser;
use fluent_templates::static_loader;
use minijinja::Environment;
use tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
layer::SubscriberExt,
util::SubscriberInitExt,
};
use minijinja::Environment;
use fluent_templates::static_loader;

use crate::consts::UNCATEGORIZED_URL;
use crate::utils::jinja_extra;

#[derive(Debug, Clone, Parser)]
#[command(author, version, about)]
pub struct AppOptions {
#[arg(short, long, help = "Network address to bind, can be <port>, <ip:port> or Unix socket path")]
#[arg(
short,
long,
help = "Network address to bind, can be <port>, <ip:port> or Unix socket path"
)]
pub bind: Option<String>,
#[arg(short, action = clap::ArgAction::Count, help = "Verbosity")]
pub verbose: u8,
Expand All @@ -27,7 +31,7 @@ pub fn is_journald_connected() -> bool {
// In desktop (development): JOURNAL_STREAM and TERM are set. We want to log to console.
// In service: JOURNAL_STREAM is set. TERM is set if stderr is connected to tty instead of journald.
if env::var_os("JOURNAL_STREAM").is_none() {
return false
return false;
}
let term_available = env::var("TERM").map_or(false, |s| !s.is_empty());
!term_available
Expand All @@ -46,14 +50,12 @@ pub fn config_logging(app_opt: &AppOptions) {
_ => LevelFilter::TRACE,
}
};
let command_directives = format!("quanweb={level},axum_login={level},tower_http={level}");
let directives = format!("{level}");
let filter = EnvFilter::builder()
.with_default_directive(LevelFilter::WARN.into())
.parse(command_directives)
.unwrap();
.parse_lossy(directives);

let registry = tracing_subscriber::registry()
.with(filter);
let registry = tracing_subscriber::registry().with(filter);

if is_journald_connected() {
if let Ok(journald_layer) = tracing_journald::layer() {
Expand All @@ -62,7 +64,6 @@ pub fn config_logging(app_opt: &AppOptions) {
} else {
registry.with(tracing_subscriber::fmt::layer()).init();
}

}

pub fn config_jinja() -> Result<Environment<'static>, io::Error> {
Expand Down

0 comments on commit 52368f9

Please sign in to comment.