add support for multiple log formats (#517)

this commit adds the tracing-subscriber crate and use its formatters to
support multiple log formats.

More details in
https://github.com/postgresml/pgcat/issues/464#issuecomment-1641430299

Signed-off-by: Sebastian Webber <sebastian@swebber.me>
This commit is contained in:
Sebastian Webber
2023-07-19 03:07:13 -03:00
committed by GitHub
parent 7bdb4e5cd9
commit f85e5bd9e8
6 changed files with 117 additions and 93 deletions

View File

@@ -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);