diff --git a/ofborg/src/asynccmd.rs b/ofborg/src/asynccmd.rs index ec72565..a6c29fe 100644 --- a/ofborg/src/asynccmd.rs +++ b/ofborg/src/asynccmd.rs @@ -4,6 +4,8 @@ use std::process::{Child, Command, ExitStatus, Stdio}; use std::sync::mpsc::{self, sync_channel, Receiver, SyncSender}; use std::thread::{self, JoinHandle}; +use tracing::{debug, error, info}; + // Specifically set to fall under 1/2 of the AMQP library's // SyncSender limitation. const OUT_CHANNEL_BUFFER_SIZE: usize = 30; diff --git a/ofborg/src/bin/build-faker.rs b/ofborg/src/bin/build-faker.rs index ad51c40..778e336 100644 --- a/ofborg/src/bin/build-faker.rs +++ b/ofborg/src/bin/build-faker.rs @@ -1,4 +1,3 @@ -use log::{info, log}; use ofborg::commentparser; use ofborg::config; use ofborg::easyamqp; @@ -8,6 +7,8 @@ use ofborg::worker; use std::env; +use tracing::info; + fn main() { let cfg = config::load(env::args().nth(1).unwrap().as_ref()); ofborg::setup_log(); diff --git a/ofborg/src/bin/builder.rs b/ofborg/src/bin/builder.rs index d5529e1..7b4a9b3 100644 --- a/ofborg/src/bin/builder.rs +++ b/ofborg/src/bin/builder.rs @@ -3,7 +3,7 @@ use std::error::Error; use std::path::Path; use async_std::task; -use log::{info, log, warn}; +use tracing::{info, warn}; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::easylapin; diff --git a/ofborg/src/bin/evaluation-filter.rs b/ofborg/src/bin/evaluation-filter.rs index 96e65ce..91d519f 100644 --- a/ofborg/src/bin/evaluation-filter.rs +++ b/ofborg/src/bin/evaluation-filter.rs @@ -1,5 +1,4 @@ use amqp::Basic; -use log::{info, log}; use ofborg::config; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::tasks; @@ -7,6 +6,8 @@ use ofborg::worker; use std::env; +use tracing::info; + fn main() { let cfg = config::load(env::args().nth(1).unwrap().as_ref()); ofborg::setup_log(); diff --git a/ofborg/src/bin/github-comment-filter.rs b/ofborg/src/bin/github-comment-filter.rs index c872756..af18796 100644 --- a/ofborg/src/bin/github-comment-filter.rs +++ b/ofborg/src/bin/github-comment-filter.rs @@ -1,5 +1,3 @@ -use amqp::Basic; -use log::{info, log}; use ofborg::config; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::tasks; @@ -7,6 +5,9 @@ use ofborg::worker; use std::env; +use amqp::Basic; +use tracing::info; + fn main() { let cfg = config::load(env::args().nth(1).unwrap().as_ref()); ofborg::setup_log(); diff --git a/ofborg/src/bin/github-comment-poster.rs b/ofborg/src/bin/github-comment-poster.rs index cca3925..25d0c66 100644 --- a/ofborg/src/bin/github-comment-poster.rs +++ b/ofborg/src/bin/github-comment-poster.rs @@ -1,5 +1,3 @@ -use amqp::Basic; -use log::{info, log}; use ofborg::config; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::tasks; @@ -7,6 +5,9 @@ use ofborg::worker; use std::env; +use amqp::Basic; +use tracing::info; + fn main() { let cfg = config::load(env::args().nth(1).unwrap().as_ref()); ofborg::setup_log(); diff --git a/ofborg/src/bin/log-message-collector.rs b/ofborg/src/bin/log-message-collector.rs index b49a809..a9e5cef 100644 --- a/ofborg/src/bin/log-message-collector.rs +++ b/ofborg/src/bin/log-message-collector.rs @@ -1,4 +1,3 @@ -use log::{info, log}; use ofborg::config; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::tasks; @@ -7,6 +6,8 @@ use ofborg::worker; use std::env; use std::path::PathBuf; +use tracing::info; + fn main() { let cfg = config::load(env::args().nth(1).unwrap().as_ref()); ofborg::setup_log(); diff --git a/ofborg/src/bin/log-message-generator.rs b/ofborg/src/bin/log-message-generator.rs index 467d791..6ab7915 100644 --- a/ofborg/src/bin/log-message-generator.rs +++ b/ofborg/src/bin/log-message-generator.rs @@ -1,4 +1,3 @@ -use log::{info, log}; use ofborg::config; use ofborg::easyamqp; use ofborg::message::{buildjob, Pr, Repo}; @@ -9,6 +8,8 @@ use std::env; use std::thread; use std::time::Duration; +use tracing::info; + fn main() { let cfg = config::load(env::args().nth(1).unwrap().as_ref()); ofborg::setup_log(); diff --git a/ofborg/src/bin/mass-rebuilder.rs b/ofborg/src/bin/mass-rebuilder.rs index 353afe6..7c098b6 100644 --- a/ofborg/src/bin/mass-rebuilder.rs +++ b/ofborg/src/bin/mass-rebuilder.rs @@ -1,5 +1,3 @@ -use amqp::Basic; -use log::{error, info, log}; use ofborg::checkout; use ofborg::config; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; @@ -11,6 +9,9 @@ use std::env; use std::path::Path; use std::process; +use amqp::Basic; +use tracing::{error, info}; + fn main() { let memory_info = sys_info::mem_info().expect("Unable to get memory information from OS"); diff --git a/ofborg/src/bin/stats.rs b/ofborg/src/bin/stats.rs index a835cbf..06a4ffc 100644 --- a/ofborg/src/bin/stats.rs +++ b/ofborg/src/bin/stats.rs @@ -1,12 +1,13 @@ -use amqp::Basic; -use hyper::server::{Request, Response, Server}; -use log::{info, log}; use ofborg::easyamqp::{ChannelExt, ConsumerExt}; use ofborg::{config, easyamqp, stats, tasks, worker}; use std::env; use std::thread; +use amqp::Basic; +use hyper::server::{Request, Response, Server}; +use tracing::info; + fn main() { let cfg = config::load(env::args().nth(1).unwrap().as_ref()); ofborg::setup_log(); diff --git a/ofborg/src/checkout.rs b/ofborg/src/checkout.rs index 10cd7de..8e4109b 100644 --- a/ofborg/src/checkout.rs +++ b/ofborg/src/checkout.rs @@ -6,6 +6,8 @@ use std::io::{Error, ErrorKind}; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; +use tracing::info; + pub struct CachedCloner { root: PathBuf, } diff --git a/ofborg/src/clone.rs b/ofborg/src/clone.rs index cba44b6..4b177ae 100644 --- a/ofborg/src/clone.rs +++ b/ofborg/src/clone.rs @@ -6,6 +6,8 @@ use std::io::{Error, ErrorKind}; use std::path::PathBuf; use std::process::{Command, Stdio}; +use tracing::{debug, info, warn}; + pub struct Lock { lock: Option, } diff --git a/ofborg/src/commentparser.rs b/ofborg/src/commentparser.rs index 16eaa52..8488894 100644 --- a/ofborg/src/commentparser.rs +++ b/ofborg/src/commentparser.rs @@ -1,4 +1,5 @@ use nom::types::CompleteStr; +use tracing::warn; pub fn parse(text: &str) -> Option> { let instructions: Vec = text diff --git a/ofborg/src/commitstatus.rs b/ofborg/src/commitstatus.rs index 3ad3d1b..8ee6dd6 100644 --- a/ofborg/src/commitstatus.rs +++ b/ofborg/src/commitstatus.rs @@ -1,3 +1,5 @@ +use tracing::warn; + pub struct CommitStatus<'a> { api: hubcaps::statuses::Statuses<'a>, sha: String, diff --git a/ofborg/src/config.rs b/ofborg/src/config.rs index 8df12b0..5b4ab3e 100644 --- a/ofborg/src/config.rs +++ b/ofborg/src/config.rs @@ -1,16 +1,17 @@ use crate::acl; use crate::nix::Nix; -use hubcaps::{Credentials, Github, InstallationTokenGenerator, JWTCredentials}; -use hyper::net::HttpsConnector; -use hyper::Client; -use hyper_native_tls::NativeTlsClient; - use std::collections::HashMap; use std::fs::File; use std::io::Read; use std::path::{Path, PathBuf}; +use hubcaps::{Credentials, Github, InstallationTokenGenerator, JWTCredentials}; +use hyper::net::HttpsConnector; +use hyper::Client; +use hyper_native_tls::NativeTlsClient; +use tracing::{debug, error, info, warn}; + #[derive(Serialize, Deserialize, Debug)] pub struct Config { pub runner: RunnerConfig, diff --git a/ofborg/src/easyamqp.rs b/ofborg/src/easyamqp.rs index 3104e24..01646cd 100644 --- a/ofborg/src/easyamqp.rs +++ b/ofborg/src/easyamqp.rs @@ -2,6 +2,7 @@ use crate::config::RabbitMQConfig; use crate::ofborg; use amqp::Basic; +use tracing::info; pub struct ConsumeConfig { /// Specifies the name of the queue to consume from. diff --git a/ofborg/src/easylapin.rs b/ofborg/src/easylapin.rs index c5c8eb6..f060519 100644 --- a/ofborg/src/easylapin.rs +++ b/ofborg/src/easylapin.rs @@ -21,6 +21,7 @@ use lapin::types::{AMQPValue, FieldTable}; use lapin::{ BasicProperties, Channel, CloseOnDrop, Connection, ConnectionProperties, ExchangeKind, }; +use tracing::debug; pub fn from_config(cfg: &RabbitMQConfig) -> Result, lapin::Error> { let mut props = FieldTable::default(); @@ -146,7 +147,7 @@ impl ConsumerExt for NotifyChannel { let mut chan = self.0; Ok(Box::pin(async move { while let Some(Ok(deliver)) = consumer.next().await { - log::debug!("delivery {}", deliver.delivery_tag); + debug!("delivery {}", deliver.delivery_tag); let mut receiver = ChannelNotificationReceiver { channel: &mut chan, deliver: &deliver, @@ -174,25 +175,25 @@ async fn action_deliver( ) -> Result<(), lapin::Error> { match action { Action::Ack => { - log::debug!("action ack"); + debug!("action ack"); chan.basic_ack(deliver.delivery_tag, BasicAckOptions::default()) .await } Action::NackRequeue => { - log::debug!("action nack requeue"); + debug!("action nack requeue"); let mut opts = BasicNackOptions::default(); opts.requeue = true; chan.basic_nack(deliver.delivery_tag, opts).await } Action::NackDump => { - log::debug!("action nack dump"); + debug!("action nack dump"); chan.basic_nack(deliver.delivery_tag, BasicNackOptions::default()) .await } Action::Publish(mut msg) => { let exch = msg.exchange.take().unwrap_or_else(|| "".to_owned()); let key = msg.routing_key.take().unwrap_or_else(|| "".to_owned()); - log::debug!("action publish {}", exch); + debug!("action publish {}", exch); let mut props = BasicProperties::default().with_delivery_mode(2); // persistent. diff --git a/ofborg/src/lib.rs b/ofborg/src/lib.rs index f5bc48a..4f15971 100644 --- a/ofborg/src/lib.rs +++ b/ofborg/src/lib.rs @@ -8,13 +8,11 @@ #[macro_use] extern crate serde_derive; -#[macro_use] -extern crate log; - #[macro_use] extern crate nom; -use std::env; +use tracing_subscriber::prelude::*; +use tracing_subscriber::EnvFilter; pub mod acl; pub mod asynccmd; @@ -90,11 +88,15 @@ pub mod ofborg { } pub fn setup_log() { - if env::var("RUST_LOG").is_err() { - env::set_var("RUST_LOG", "info"); - env_logger::init().unwrap(); - info!("Defaulting RUST_LOG environment variable to info"); - } else { - env_logger::init().unwrap(); - } + let fmt_layer = tracing_subscriber::fmt::layer(); + let filter_layer = EnvFilter::try_from_default_env() + .or_else(|_| EnvFilter::try_new("info")) + .unwrap(); + + tracing_subscriber::registry() + .with(filter_layer) + .with(fmt_layer) + .init(); + + tracing::info!("Logging configured"); } diff --git a/ofborg/src/nixenv.rs b/ofborg/src/nixenv.rs index 6915ec7..000661a 100644 --- a/ofborg/src/nixenv.rs +++ b/ofborg/src/nixenv.rs @@ -8,6 +8,8 @@ use std::fs::{self, File}; use std::io::{self, BufRead, BufReader, Read, Seek, SeekFrom, Write}; use std::path::PathBuf; +use tracing::warn; + pub struct HydraNixEnv { path: PathBuf, nix: nix::Nix, diff --git a/ofborg/src/outpathdiff.rs b/ofborg/src/outpathdiff.rs index 86de6ea..e482b5d 100644 --- a/ofborg/src/outpathdiff.rs +++ b/ofborg/src/outpathdiff.rs @@ -6,6 +6,8 @@ use std::collections::{HashMap, HashSet}; use std::io::BufRead; use std::path::PathBuf; +use tracing::{debug, info, trace}; + pub struct OutPathDiff { calculator: HydraNixEnv, pub original: Option<(PackageOutPaths, EvaluationStats)>, diff --git a/ofborg/src/tagger.rs b/ofborg/src/tagger.rs index 19939ce..8ecdc7a 100644 --- a/ofborg/src/tagger.rs +++ b/ofborg/src/tagger.rs @@ -4,6 +4,8 @@ use crate::tasks; use std::collections::HashMap; +use tracing::info; + pub struct StdenvTagger { possible: Vec, selected: Vec, diff --git a/ofborg/src/tasks/build.rs b/ofborg/src/tasks/build.rs index 0d8c42f..4d3b5dc 100644 --- a/ofborg/src/tasks/build.rs +++ b/ofborg/src/tasks/build.rs @@ -6,10 +6,11 @@ use crate::nix; use crate::notifyworker; use crate::worker; -use uuid::Uuid; - use std::collections::VecDeque; +use uuid::Uuid; +use tracing::{error, info}; + pub struct BuildWorker { cloner: checkout::CachedCloner, nix: nix::Nix, diff --git a/ofborg/src/tasks/eval/nixpkgs.rs b/ofborg/src/tasks/eval/nixpkgs.rs index d8b73dd..9374d16 100644 --- a/ofborg/src/tasks/eval/nixpkgs.rs +++ b/ofborg/src/tasks/eval/nixpkgs.rs @@ -16,16 +16,17 @@ use crate::tasks::eval::{ }; use crate::tasks::evaluate::{make_gist, update_labels}; +use std::collections::HashMap; +use std::path::Path; + use chrono::Utc; use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output}; use hubcaps::gists::Gists; use hubcaps::issues::{Issue, IssueRef}; use hubcaps::repositories::Repository; +use tracing::warn; use uuid::Uuid; -use std::collections::HashMap; -use std::path::Path; - pub struct NixpkgsStrategy<'a> { job: &'a EvaluationJob, pull: &'a hubcaps::pulls::PullRequest<'a>, diff --git a/ofborg/src/tasks/eval/stdenvs.rs b/ofborg/src/tasks/eval/stdenvs.rs index fcaeb34..673f462 100644 --- a/ofborg/src/tasks/eval/stdenvs.rs +++ b/ofborg/src/tasks/eval/stdenvs.rs @@ -3,6 +3,8 @@ use crate::nix; use std::path::PathBuf; +use tracing::{info, warn}; + enum StdenvFrom { Before, After, diff --git a/ofborg/src/tasks/evaluate.rs b/ofborg/src/tasks/evaluate.rs index 751e48c..a5bf6ad 100644 --- a/ofborg/src/tasks/evaluate.rs +++ b/ofborg/src/tasks/evaluate.rs @@ -11,15 +11,16 @@ use crate::systems; use crate::tasks::eval; use crate::worker; -use hubcaps::checks::CheckRunOptions; -use hubcaps::gists::Gists; -use hubcaps::issues::Issue; - use std::collections::HashMap; use std::path::Path; use std::sync::RwLock; use std::time::Instant; +use hubcaps::checks::CheckRunOptions; +use hubcaps::gists::Gists; +use hubcaps::issues::Issue; +use tracing::{error, info, warn}; + pub struct EvaluationWorker { cloner: checkout::CachedCloner, nix: nix::Nix, diff --git a/ofborg/src/tasks/evaluationfilter.rs b/ofborg/src/tasks/evaluationfilter.rs index c8184b6..5a2f10f 100644 --- a/ofborg/src/tasks/evaluationfilter.rs +++ b/ofborg/src/tasks/evaluationfilter.rs @@ -3,6 +3,8 @@ use crate::ghevent; use crate::message::{evaluationjob, Pr, Repo}; use crate::worker; +use tracing::info; + pub struct EvaluationFilterWorker { acl: acl::ACL, } diff --git a/ofborg/src/tasks/githubcommentfilter.rs b/ofborg/src/tasks/githubcommentfilter.rs index 239fca7..03a1c0d 100644 --- a/ofborg/src/tasks/githubcommentfilter.rs +++ b/ofborg/src/tasks/githubcommentfilter.rs @@ -4,6 +4,7 @@ use crate::ghevent; use crate::message::{buildjob, evaluationjob, Pr, Repo}; use crate::worker; +use tracing::{error, info}; use uuid::Uuid; pub struct GitHubCommentWorker { diff --git a/ofborg/src/tasks/githubcommentposter.rs b/ofborg/src/tasks/githubcommentposter.rs index 82fea77..188b73a 100644 --- a/ofborg/src/tasks/githubcommentposter.rs +++ b/ofborg/src/tasks/githubcommentposter.rs @@ -6,6 +6,7 @@ use crate::worker; use chrono::{DateTime, Utc}; use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output}; +use tracing::info; pub struct GitHubCommentPoster { github_vend: GithubAppVendingMachine, diff --git a/ofborg/src/tasks/log_message_collector.rs b/ofborg/src/tasks/log_message_collector.rs index 38a0bd1..3240531 100644 --- a/ofborg/src/tasks/log_message_collector.rs +++ b/ofborg/src/tasks/log_message_collector.rs @@ -3,12 +3,13 @@ use crate::message::buildresult::BuildResult; use crate::worker; use crate::writetoline::LineWriter; -use lru_cache::LruCache; - use std::fs::{self, File, OpenOptions}; use std::io::Write; use std::path::{Component, PathBuf}; +use lru_cache::LruCache; +use tracing::warn; + #[derive(Eq, PartialEq, Hash, Debug, Clone)] pub struct LogFrom { routing_key: String, diff --git a/ofborg/src/tasks/statscollector.rs b/ofborg/src/tasks/statscollector.rs index 84e733e..c28707b 100644 --- a/ofborg/src/tasks/statscollector.rs +++ b/ofborg/src/tasks/statscollector.rs @@ -1,6 +1,8 @@ use crate::stats; use crate::worker; +use tracing::error; + pub struct StatCollectorWorker { events: E, collector: stats::MetricCollector, diff --git a/ofborg/src/test_scratch.rs b/ofborg/src/test_scratch.rs index e8e1884..ae20f5d 100644 --- a/ofborg/src/test_scratch.rs +++ b/ofborg/src/test_scratch.rs @@ -2,6 +2,8 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; +use tracing::debug; + pub struct TestScratch { root: PathBuf, } diff --git a/ofborg/src/worker.rs b/ofborg/src/worker.rs index 51a72ba..960917a 100644 --- a/ofborg/src/worker.rs +++ b/ofborg/src/worker.rs @@ -1,8 +1,9 @@ +use std::marker::Send; + use amqp::protocol::basic::{BasicProperties, Deliver}; use amqp::Basic; use serde::Serialize; - -use std::marker::Send; +use tracing::error; pub struct Worker { internal: T,