Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for multiple log formats #517

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ tokio-test = "0.4.2"
serde_json = "1"
itertools = "0.10"
clap = { version = "4.3.1", features = ["derive", "env"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["json"]}

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = "0.5.0"
Expand Down
22 changes: 16 additions & 6 deletions src/cmd_args.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
use clap::Parser;
use log::LevelFilter;
use clap::{Parser, ValueEnum};
use tracing::Level;

/// PgCat: Nextgen PostgreSQL Pooler
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub(crate) struct Args {
pub struct Args {
#[arg(default_value_t = String::from("pgcat.toml"), env)]
pub config_file: String,

#[arg(short, long, default_value_t = LevelFilter::Info, env)]
pub log_level: log::LevelFilter,
#[arg(short, long, default_value_t = tracing::Level::INFO, env)]
pub log_level: Level,

#[clap(short='F', long, value_enum, default_value_t=LogFormat::Text, env)]
pub log_format: LogFormat,
}

pub(crate) fn parse() -> Args {
pub fn parse() -> Args {
return Args::parse();
}

#[derive(ValueEnum, Clone, Debug)]
pub enum LogFormat {
Text,
Structured,
Debug,
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pub mod admin;
pub mod auth_passthrough;
pub mod client;
pub mod cmd_args;
pub mod config;
pub mod constants;
pub mod dns_cache;
pub mod errors;
pub mod messages;
pub mod mirrors;
pub mod multi_logger;
pub mod plugins;
pub mod pool;
pub mod prometheus;
Expand Down
19 changes: 16 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,31 @@ use std::str::FromStr;
use std::sync::Arc;
use tokio::sync::broadcast;

use pgcat::cmd_args;
use pgcat::cmd_args::LogFormat;
use pgcat::config::{get_config, reload_config, VERSION};
use pgcat::dns_cache;
use pgcat::messages::configure_socket;
use pgcat::pool::{ClientServerMap, ConnectionPool};
use pgcat::prometheus::start_metric_server;
use pgcat::stats::{Collector, Reporter, REPORTER};

mod cmd_args;
use tracing_subscriber;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = cmd_args::parse();
pgcat::multi_logger::MultiLogger::init(args.log_level).unwrap();
match args.log_format {
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);

Expand Down
83 changes: 0 additions & 83 deletions src/multi_logger.rs

This file was deleted.