Skip to content

Commit

Permalink
replaced env_logger by tokio tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed Dec 18, 2023
1 parent 4fcd032 commit 779dfef
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 52 deletions.
146 changes: 107 additions & 39 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion limitador-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ prost = "0.12"
prost-types = "0.12"
serde_yaml = "0.9"
log = "0.4"
env_logger = "0.10.0"
tracing = "0.1.40"
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
url = "2"
actix-web = "4.1"
actix-rt = "2"
Expand Down
2 changes: 1 addition & 1 deletion limitador-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use crate::envoy_rls::server::RateLimitHeaders;
use limitador::storage;
use log::LevelFilter;
use tracing::level_filters::LevelFilter;

#[derive(Debug)]
pub struct Configuration {
Expand Down
24 changes: 13 additions & 11 deletions limitador-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::envoy_rls::server::{run_envoy_rls_server, RateLimitHeaders};
use crate::http_api::server::run_http_server;
use clap::{value_parser, Arg, ArgAction, Command};
use const_format::formatcp;
use env_logger::Builder;
use limitador::counter::Counter;
use limitador::errors::LimitadorError;
use limitador::limit::Limit;
Expand All @@ -30,7 +29,6 @@ use limitador::storage::{AsyncCounterStorage, AsyncStorage, Storage};
use limitador::{
storage, AsyncRateLimiter, AsyncRateLimiterBuilder, RateLimiter, RateLimiterBuilder,
};
use log::LevelFilter;
use notify::event::{ModifyKind, RenameMode};
use notify::{Error, Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
use std::env::VarError;
Expand All @@ -42,6 +40,7 @@ use std::{env, process};
use sysinfo::{RefreshKind, System, SystemExt};
use thiserror::Error;
use tokio::runtime::Handle;
use tracing::level_filters::LevelFilter;

mod envoy_rls;
mod http_api;
Expand Down Expand Up @@ -285,12 +284,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = {
let (config, version) = create_config();
println!("{LIMITADOR_HEADER} {version}");
let mut builder = Builder::new();
if let Some(level) = config.log_level {
builder.filter(None, level);
let builder = if let Some(level) = config.log_level {
tracing_subscriber::fmt().with_max_level(level)
} else {
builder.parse_default_env();
}
tracing_subscriber::fmt().with_max_level(
tracing_subscriber::filter::EnvFilter::from_default_env()
.max_level_hint()
.unwrap_or(LevelFilter::ERROR),
)
};
builder.init();

info!("Version: {}", version);
Expand Down Expand Up @@ -749,10 +751,10 @@ fn create_config() -> (Configuration, &'static str) {

config.log_level = match matches.get_count("v") {
0 => None,
1 => Some(LevelFilter::Warn),
2 => Some(LevelFilter::Info),
3 => Some(LevelFilter::Debug),
4 => Some(LevelFilter::Trace),
1 => Some(LevelFilter::WARN),
2 => Some(LevelFilter::INFO),
3 => Some(LevelFilter::DEBUG),
4 => Some(LevelFilter::TRACE),
_ => unreachable!("Verbosity should at most be 4!"),
};

Expand Down

0 comments on commit 779dfef

Please sign in to comment.