Skip to content

Commit

Permalink
Support for structured logging (JSON) txpipe#437
Browse files Browse the repository at this point in the history
 - Added json_logs feature and made the used logging library dependend on the current feature flag setting.
  • Loading branch information
4TT1L4 committed Sep 21, 2022
1 parent 2a9094f commit d7e25a7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
45 changes: 45 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 @@ -21,6 +21,7 @@ bech32 = "0.9.1"
clap = "3.2.22"
log = "0.4.17"
env_logger = "0.9.1"
json_env_logger2 = { version = "0.2", features = ["iso-timestamps", "backtrace"], optional = true }
crossterm = "0.25"
merge = "0.1.0"
config = { version = "0.13.2", default-features = false, features = [
Expand Down Expand Up @@ -79,3 +80,4 @@ fingerprint = ["murmur3"]
aws = ["aws-config", "aws-sdk-sqs", "aws-sdk-lambda", "aws-sdk-s3", "tokio"]
redissink = ["redis", "tokio"]
gcp = ["cloud-pubsub", "tokio", "web"]
json_logs = ["json_env_logger2"]
8 changes: 7 additions & 1 deletion src/bin/oura/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use config::{Config, ConfigError, Environment, File};
use log::debug;
use serde::Deserialize;

#[cfg(not(feature = "json_logs"))]
use env_logger as logger;

#[cfg(feature = "json_logs")]
use json_env_logger2 as logger;

use oura::{
pipelining::{
BootstrapResult, FilterProvider, PartialBootstrapResult, SinkProvider, SourceProvider,
Expand Down Expand Up @@ -293,7 +299,7 @@ fn bootstrap(
}

pub fn run(args: &ArgMatches) -> Result<(), Error> {
env_logger::init();
logger::init();

let explicit_config = match args.is_present("config") {
true => Some(args.value_of_t("config")?),
Expand Down
8 changes: 7 additions & 1 deletion src/bin/oura/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ use oura::sinks::stdout::Config as StdoutConfig;
use oura::sources::n2c::Config as N2CConfig;
use oura::sources::n2n::Config as N2NConfig;

#[cfg(not(feature = "json_logs"))]
use env_logger as logger;

#[cfg(feature = "json_logs")]
use json_env_logger2 as logger;

#[cfg(feature = "logs")]
use oura::sinks::logs::Config as LogsConfig;

Expand Down Expand Up @@ -58,7 +64,7 @@ fn bootstrap_sink(sink: DumpSink, input: StageReceiver, utils: Arc<Utils>) -> Bo
}

pub fn run(args: &ArgMatches) -> Result<(), Error> {
env_logger::builder()
logger::builder()
.filter_module("oura::dump", log::LevelFilter::Info)
.init();

Expand Down
8 changes: 7 additions & 1 deletion src/bin/oura/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ use oura::sources::n2n::Config as N2NConfig;

use crate::Error;

#[cfg(not(feature = "json_logs"))]
use env_logger as logger;

#[cfg(feature = "json_logs")]
use json_env_logger2 as logger;

#[derive(Clone, Debug, Deserialize)]
pub enum PeerMode {
AsNode,
Expand All @@ -39,7 +45,7 @@ enum WatchSource {
}

pub fn run(args: &ArgMatches) -> Result<(), Error> {
env_logger::builder()
logger::builder()
.filter_level(log::LevelFilter::Error)
.init();

Expand Down

0 comments on commit d7e25a7

Please sign in to comment.