Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
Syslog support (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency authored May 27, 2022
1 parent 82ea6b0 commit 3746bc9
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 65 deletions.
72 changes: 19 additions & 53 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion src/http_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ many-kvstore = { path = "../many-kvstore" }
new_mime_guess = "4.0.0"
tiny_http = "0.9.0"
tracing = "0.1.29"
tracing-subscriber = "0.3.3"
tracing-subscriber = "0.3"
tracing-syslog = { git = "https://github.com/max-heller/tracing-syslog.git", rev = "6ff222831d7a78f1068d4c8af94dea215b07f114" }
tokio = { version = "1.12.0", features = [ "full" ] }
29 changes: 28 additions & 1 deletion src/http_proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ use tiny_http::{Header, Method, Response, StatusCode};
use tracing::warn;
use tracing_subscriber::filter::LevelFilter;

#[derive(clap::ArgEnum, Clone)]
enum LogStrategy {
Terminal,
Syslog,
}

#[derive(Parser)]
struct Opts {
/// Many server URL to connect to. It must implement a KV-Store attribute.
Expand All @@ -33,6 +39,10 @@ struct Opts {
/// Suppress all output logging. Can be used multiple times to suppress more.
#[clap(short, long, parse(from_occurrences))]
quiet: i8,

/// Use given logging strategy
#[clap(long, arg_enum, default_value_t = LogStrategy::Terminal)]
logmode: LogStrategy,
}

fn main() {
Expand All @@ -43,6 +53,7 @@ fn main() {
server_id,
verbose,
quiet,
logmode,
} = Opts::parse();

let verbose_level = 2 + verbose - quiet;
Expand All @@ -55,7 +66,23 @@ fn main() {
x if x < 0 => LevelFilter::OFF,
_ => unreachable!(),
};
tracing_subscriber::fmt().with_max_level(log_level).init();

let subscriber = tracing_subscriber::fmt::Subscriber::builder().with_max_level(log_level);

match logmode {
LogStrategy::Terminal => {
let subscriber = subscriber.with_writer(std::io::stderr);
subscriber.init();
}
LogStrategy::Syslog => {
let identity = std::ffi::CStr::from_bytes_with_nul(b"http_proxy\0").unwrap();
let (options, facility) = Default::default();
let syslog = tracing_syslog::Syslog::new(identity, options, facility).unwrap();

let subscriber = subscriber.with_writer(syslog);
subscriber.init();
}
};

let server_id = server_id.unwrap_or_default();
let key = pem.map_or_else(CoseKeyIdentity::anonymous, |p| {
Expand Down
3 changes: 2 additions & 1 deletion src/kvstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ many = { git = "https://github.com/liftedinit/many-rs.git", rev = "c80f6314957bc
many-client = { git = "https://github.com/liftedinit/many-rs.git", rev = "c80f6314957bc0d7b084c883367bc012b5d473f7" }
many-kvstore = { path = "../many-kvstore" }
tracing = "0.1.29"
tracing-subscriber = "0.3.3"
tracing-subscriber = "0.3"
tracing-syslog = { git = "https://github.com/max-heller/tracing-syslog.git", rev = "6ff222831d7a78f1068d4c8af94dea215b07f114" }
tokio = { version = "1.12.0", features = [ "full" ] }
28 changes: 27 additions & 1 deletion src/kvstore/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ use std::path::PathBuf;
use tracing::{error, trace};
use tracing_subscriber::filter::LevelFilter;

#[derive(clap::ArgEnum, Clone, Debug)]
enum LogStrategy {
Terminal,
Syslog,
}

#[derive(Parser)]
struct Opts {
/// Many server URL to connect to.
Expand All @@ -30,6 +36,10 @@ struct Opts {
#[clap(short, long, parse(from_occurrences))]
quiet: i8,

/// Use given logging strategy
#[clap(long, arg_enum, default_value_t = LogStrategy::Terminal)]
logmode: LogStrategy,

#[clap(subcommand)]
subcommand: SubCommand,
}
Expand Down Expand Up @@ -131,6 +141,7 @@ fn main() {
subcommand,
verbose,
quiet,
logmode,
} = Opts::parse();

let verbose_level = 2 + verbose - quiet;
Expand All @@ -143,7 +154,22 @@ fn main() {
x if x < 0 => LevelFilter::OFF,
_ => unreachable!(),
};
tracing_subscriber::fmt().with_max_level(log_level).init();
let subscriber = tracing_subscriber::fmt::Subscriber::builder().with_max_level(log_level);

match logmode {
LogStrategy::Terminal => {
let subscriber = subscriber.with_writer(std::io::stderr);
subscriber.init();
}
LogStrategy::Syslog => {
let identity = std::ffi::CStr::from_bytes_with_nul(b"kvstore\0").unwrap();
let (options, facility) = Default::default();
let syslog = tracing_syslog::Syslog::new(identity, options, facility).unwrap();

let subscriber = subscriber.with_writer(syslog);
subscriber.init();
}
};

let server_id = server_id.unwrap_or_default();
let key = pem.map_or_else(CoseKeyIdentity::anonymous, |p| {
Expand Down
3 changes: 2 additions & 1 deletion src/ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ regex = "1.5.4"
ring = "0.17.0-alpha.10"
rpassword = "6.0"
tracing = "0.1.29"
tracing-subscriber = "0.3.3"
tracing-subscriber = "0.3"
tracing-syslog = { git = "https://github.com/max-heller/tracing-syslog.git", rev = "6ff222831d7a78f1068d4c8af94dea215b07f114" }
tokio = { version = "1.12.0", features = [ "full" ] }
28 changes: 27 additions & 1 deletion src/ledger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ use std::time::Duration;

mod multisig;

#[derive(clap::ArgEnum, Clone, Debug)]
enum LogStrategy {
Terminal,
Syslog,
}

#[derive(Clone, Debug)]
#[repr(transparent)]
struct Amount(pub BigUint);
Expand Down Expand Up @@ -90,6 +96,10 @@ struct Opts {
#[clap(short, long, parse(from_occurrences))]
quiet: i8,

/// Use given logging strategy
#[clap(long, arg_enum, default_value_t = LogStrategy::Terminal)]
logmode: LogStrategy,

#[clap(subcommand)]
subcommand: SubCommand,
}
Expand Down Expand Up @@ -302,6 +312,7 @@ fn main() {
subcommand,
verbose,
quiet,
logmode,
} = Opts::parse();

let verbose_level = 2 + verbose - quiet;
Expand All @@ -314,7 +325,22 @@ fn main() {
x if x < 0 => LevelFilter::OFF,
_ => unreachable!(),
};
tracing_subscriber::fmt().with_max_level(log_level).init();
let subscriber = tracing_subscriber::fmt::Subscriber::builder().with_max_level(log_level);

match logmode {
LogStrategy::Terminal => {
let subscriber = subscriber.with_writer(std::io::stderr);
subscriber.init();
}
LogStrategy::Syslog => {
let identity = std::ffi::CStr::from_bytes_with_nul(b"ledger\0").unwrap();
let (options, facility) = Default::default();
let syslog = tracing_syslog::Syslog::new(identity, options, facility).unwrap();

let subscriber = subscriber.with_writer(syslog);
subscriber.init();
}
};

let server_id = server_id.unwrap_or_default();
let key = if let (Some(module), Some(slot), Some(keyid)) = (module, slot, keyid) {
Expand Down
3 changes: 2 additions & 1 deletion src/many-abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git",
tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git" }
tokio = { version = "1.13.0", features = [ "full" ] }
tracing = "0.1.28"
tracing-subscriber = "0.2.24"
tracing-subscriber = "0.3"
tracing-syslog = { git = "https://github.com/max-heller/tracing-syslog.git", rev = "6ff222831d7a78f1068d4c8af94dea215b07f114" }
Loading

0 comments on commit 3746bc9

Please sign in to comment.