mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-28 03:06:29 +00:00
add --no-color option to disable colors in the terminal (#518)
add --no-color option to disable colors this commit adds a new option to disable colors in the terminal and also moves the logger configuration to a different crate. Signed-off-by: Sebastian Webber <sebastian@swebber.me>
This commit is contained in:
@@ -13,6 +13,15 @@ pub struct Args {
|
|||||||
|
|
||||||
#[clap(short='F', long, value_enum, default_value_t=LogFormat::Text, env)]
|
#[clap(short='F', long, value_enum, default_value_t=LogFormat::Text, env)]
|
||||||
pub log_format: LogFormat,
|
pub log_format: LogFormat,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
short,
|
||||||
|
long,
|
||||||
|
default_value_t = false,
|
||||||
|
env,
|
||||||
|
help = "disable colors in the log output"
|
||||||
|
)]
|
||||||
|
pub no_color: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse() -> Args {
|
pub fn parse() -> Args {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ pub mod config;
|
|||||||
pub mod constants;
|
pub mod constants;
|
||||||
pub mod dns_cache;
|
pub mod dns_cache;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
pub mod logger;
|
||||||
pub mod messages;
|
pub mod messages;
|
||||||
pub mod mirrors;
|
pub mod mirrors;
|
||||||
pub mod plugins;
|
pub mod plugins;
|
||||||
|
|||||||
14
src/logger.rs
Normal file
14
src/logger.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
use crate::cmd_args::{Args, LogFormat};
|
||||||
|
use tracing_subscriber;
|
||||||
|
|
||||||
|
pub fn init(args: &Args) {
|
||||||
|
let trace_sub = tracing_subscriber::fmt()
|
||||||
|
.with_max_level(args.log_level)
|
||||||
|
.with_ansi(!args.no_color);
|
||||||
|
|
||||||
|
match args.log_format {
|
||||||
|
LogFormat::Structured => trace_sub.json().init(),
|
||||||
|
LogFormat::Debug => trace_sub.pretty().init(),
|
||||||
|
_ => trace_sub.init(),
|
||||||
|
};
|
||||||
|
}
|
||||||
17
src/main.rs
17
src/main.rs
@@ -62,30 +62,17 @@ use std::sync::Arc;
|
|||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
use pgcat::cmd_args;
|
use pgcat::cmd_args;
|
||||||
use pgcat::cmd_args::LogFormat;
|
|
||||||
use pgcat::config::{get_config, reload_config, VERSION};
|
use pgcat::config::{get_config, reload_config, VERSION};
|
||||||
use pgcat::dns_cache;
|
use pgcat::dns_cache;
|
||||||
|
use pgcat::logger;
|
||||||
use pgcat::messages::configure_socket;
|
use pgcat::messages::configure_socket;
|
||||||
use pgcat::pool::{ClientServerMap, ConnectionPool};
|
use pgcat::pool::{ClientServerMap, ConnectionPool};
|
||||||
use pgcat::prometheus::start_metric_server;
|
use pgcat::prometheus::start_metric_server;
|
||||||
use pgcat::stats::{Collector, Reporter, REPORTER};
|
use pgcat::stats::{Collector, Reporter, REPORTER};
|
||||||
use tracing_subscriber;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = cmd_args::parse();
|
let args = cmd_args::parse();
|
||||||
match args.log_format {
|
logger::init(&args);
|
||||||
LogFormat::Structured => tracing_subscriber::fmt()
|
|
||||||
.json()
|
|
||||||
.with_max_level(args.log_level)
|
|
||||||
.init(),
|
|
||||||
LogFormat::Debug => tracing_subscriber::fmt()
|
|
||||||
.pretty()
|
|
||||||
.with_max_level(args.log_level)
|
|
||||||
.init(),
|
|
||||||
_ => tracing_subscriber::fmt()
|
|
||||||
.with_max_level(args.log_level)
|
|
||||||
.init(),
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("Welcome to PgCat! Meow. (Version {})", VERSION);
|
info!("Welcome to PgCat! Meow. (Version {})", VERSION);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user