Skip to content

Commit

Permalink
Add loglevel command line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Aug 14, 2023
1 parent bffd8bd commit 2e78f20
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
12 changes: 12 additions & 0 deletions bbox-core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ pub struct GlobalArgs {
/// Config file (Default: bbox.toml)
#[arg(short, long, value_name = "FILE")]
pub config: Option<PathBuf>,
/// Log level (Default: info)
#[arg(long)]
pub loglevel: Option<Loglevel>,
}

#[derive(clap::ValueEnum, Clone, Debug)]
pub enum Loglevel {
Error,
Warn,
Info,
Debug,
Trace,
}

#[derive(Parser, Debug)]
Expand Down
18 changes: 15 additions & 3 deletions bbox-core/src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use crate::cli::Loglevel;
use std::env;

pub fn init() {
if env::var("RUST_LOG").is_err() {
env::set_var(
pub fn init(level: Option<Loglevel>) {
if let Some(level) = level {
let levelstr = match level {
Loglevel::Error => "error",
Loglevel::Warn => "warn",
Loglevel::Info => "info",
Loglevel::Debug => "debug,tokio=info",
Loglevel::Trace => "trace",
};
env::set_var("RUST_LOG", levelstr);
} else {
if env::var("RUST_LOG").is_err() {
env::set_var(
"RUST_LOG",
"info,bbox_map_server=debug,bbox_feature_server=debug,bbox_frontend=debug,sqlx=warn",
);
}
}
env_logger::init();
}
2 changes: 1 addition & 1 deletion bbox-core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl OgcApiService for CoreService {
if let Some(config) = args.config {
env::set_var("BBOX_CONFIG", config);
}
logger::init();
logger::init(args.loglevel);

self.web_config = WebserverCfg::from_config();
let auth_cfg = AuthCfg::from_config();
Expand Down
20 changes: 10 additions & 10 deletions bbox-tile-server/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ pub enum Commands {
#[derive(Debug, Args)]
pub struct SeedArgs {
/// tile set name
#[arg(long, value_parser)]
#[arg(long)]
pub tileset: String,
/// Minimum zoom level
#[arg(long, value_parser)]
#[arg(long)]
pub minzoom: Option<u8>,
/// Maximum zoom level
#[arg(long, value_parser)]
#[arg(long)]
pub maxzoom: Option<u8>,
/// Extent minx,miny,maxx,maxy (in grid reference system)
#[arg(long, value_parser)]
#[arg(long)]
pub extent: Option<String>,
/// S3 path to upload to (e.g. s3://tiles)
#[arg(long, group = "output_s3", conflicts_with = "output_files")]
Expand All @@ -64,20 +64,20 @@ pub struct SeedArgs {
#[arg(long, group = "output_files", conflicts_with = "output_s3")]
pub base_dir: Option<String>,
/// Number of threads to use, defaults to number of logical cores
#[arg(short, long, value_parser)]
#[arg(short, long)]
pub threads: Option<usize>,
/// Size of tasks queue for parallel processing
#[arg(long, value_parser)]
#[arg(long)]
pub tasks: Option<usize>,
/// Overwrite previously cached tiles
#[arg(long, value_parser)]
#[arg(long)]
pub overwrite: Option<bool>,
}

#[derive(Debug, Args)]
pub struct UploadArgs {
/// Base directory of input files
#[arg(short, long, value_parser)]
#[arg(short, long)]
pub srcdir: std::path::PathBuf,
/// S3 path to upload to (e.g. s3://tiles)
#[arg(long, group = "output_s3")]
Expand All @@ -86,10 +86,10 @@ pub struct UploadArgs {
#[arg(short, long, value_enum, default_value("tasks"))]
pub mode: Mode,
/// Number of threads to use, defaults to number of logical cores
#[arg(short, long, value_parser)]
#[arg(short, long)]
pub threads: Option<usize>,
/// Size of tasks queue for parallel processing
#[arg(long, value_parser)]
#[arg(long)]
pub tasks: Option<usize>,
}

Expand Down

0 comments on commit 2e78f20

Please sign in to comment.