Skip to content

Commit

Permalink
chore(riklet): use conventional logger methods
Browse files Browse the repository at this point in the history
Signed-off-by: AlexandreBrg <[email protected]>
  • Loading branch information
alexandrebrg committed Apr 17, 2023
1 parent 0948e1e commit ebf8f7a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
4 changes: 2 additions & 2 deletions riklet/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tracing_subscriber::field::debug;

use thiserror::Error;
use tonic::{transport::Channel, Request, Streaming};
use tracing::{debug, error, event, Level};
use tracing::{debug, error, event, info, Level};

const METRICS_UPDATER_INTERVAL: u64 = 15 * 1000;

Expand Down Expand Up @@ -148,8 +148,8 @@ impl Riklet {
}

pub async fn run(&mut self) -> Result<()> {
event!(Level::INFO, "Riklet is running.");
self.start_metrics_updater();
info!("Riklet is running");

while let Some(workload) = self
.stream
Expand Down
4 changes: 1 addition & 3 deletions riklet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ use tracing::error;

#[tokio::main]
async fn main() -> Result<()> {
init_logger(Some("debug".to_string()))?;
init_logger()?;

// run a function to test #[instrument] macro
// test_instrument();
// If the process doesn't have root privileges, exit and display error.
if !nix::unistd::Uid::effective().is_root() {
error!("Riklet must run with root privileges.");
Expand Down
19 changes: 4 additions & 15 deletions riklet/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;
use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, EnvFilter, Registry};

pub fn banner() {
println!(
Expand All @@ -14,19 +13,9 @@ pub fn banner() {
);
}

pub fn init_logger(log_level: Option<String>) -> Result<()> {
let logger = tracing_subscriber::fmt::layer().json();
// Try to get the log level from the environment variable `RUST_LOG`.
// If the variable is not defined, then use the cli argument or the default value 'info' if neither is defined
let env_filter = EnvFilter::try_from_default_env()
.or_else(|_| {
let level = log_level.unwrap_or_else(|| "info".to_string());
EnvFilter::try_new(level.as_str())
})?
.add_directive("h2=OFF".parse().unwrap()); // disable all events from the `h2` crate;

let collector = Registry::default().with(logger).with(env_filter);
tracing::subscriber::set_global_default(collector)?;

pub fn init_logger() -> Result<()> {
let subscriber = tracing_subscriber::fmt().compact().finish();
tracing::subscriber::set_global_default(subscriber)
.expect("Failed to initiate the logger subscriber");
Ok(())
}
4 changes: 2 additions & 2 deletions scheduler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ mod state_manager;
use crate::config_parser::ConfigParser;
use crate::grpc::GRPCService;
use crate::state_manager::{StateManager, StateManagerEvent};
use env_logger::Env;

use proto::common::worker_status::Status;
use proto::common::{ResourceStatus, WorkerMetric as WorkerMetricProto, WorkerStatus};
use proto::controller::controller_server::ControllerServer;
use proto::worker::worker_server::WorkerServer;
use scheduler::Event;
use scheduler::{Controller, SchedulerError, Worker, WorkerRegisterChannelType};
use std::default::Default;

use std::net::{SocketAddr, SocketAddrV4};
use std::sync::Arc;
use tracing::{debug, error, info, warn};
Expand Down

0 comments on commit ebf8f7a

Please sign in to comment.