Skip to content

Commit 08d4f7f

Browse files
committed
chore(riklet): use conventional logger methods
Signed-off-by: AlexandreBrg <[email protected]>
1 parent 0948e1e commit 08d4f7f

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

riklet/src/core.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tracing_subscriber::field::debug;
1515

1616
use thiserror::Error;
1717
use tonic::{transport::Channel, Request, Streaming};
18-
use tracing::{debug, error, event, Level};
18+
use tracing::{debug, error, event, Level, info};
1919

2020
const METRICS_UPDATER_INTERVAL: u64 = 15 * 1000;
2121

@@ -148,8 +148,8 @@ impl Riklet {
148148
}
149149

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

154154
while let Some(workload) = self
155155
.stream

riklet/src/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ use tracing::error;
1717

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

22-
// run a function to test #[instrument] macro
23-
// test_instrument();
2422
// If the process doesn't have root privileges, exit and display error.
2523
if !nix::unistd::Uid::effective().is_root() {
2624
error!("Riklet must run with root privileges.");

riklet/src/utils.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use anyhow::Result;
2-
use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, EnvFilter, Registry};
32

43
pub fn banner() {
54
println!(
@@ -14,19 +13,9 @@ pub fn banner() {
1413
);
1514
}
1615

17-
pub fn init_logger(log_level: Option<String>) -> Result<()> {
18-
let logger = tracing_subscriber::fmt::layer().json();
19-
// Try to get the log level from the environment variable `RUST_LOG`.
20-
// If the variable is not defined, then use the cli argument or the default value 'info' if neither is defined
21-
let env_filter = EnvFilter::try_from_default_env()
22-
.or_else(|_| {
23-
let level = log_level.unwrap_or_else(|| "info".to_string());
24-
EnvFilter::try_new(level.as_str())
25-
})?
26-
.add_directive("h2=OFF".parse().unwrap()); // disable all events from the `h2` crate;
27-
28-
let collector = Registry::default().with(logger).with(env_filter);
29-
tracing::subscriber::set_global_default(collector)?;
30-
16+
pub fn init_logger() -> Result<()> {
17+
let subscriber = tracing_subscriber::fmt().compact().finish();
18+
tracing::subscriber::set_global_default(subscriber)
19+
.expect("Failed to initiate the logger subscriber");
3120
Ok(())
3221
}

scheduler/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ mod state_manager;
55
use crate::config_parser::ConfigParser;
66
use crate::grpc::GRPCService;
77
use crate::state_manager::{StateManager, StateManagerEvent};
8-
use env_logger::Env;
8+
99
use proto::common::worker_status::Status;
1010
use proto::common::{ResourceStatus, WorkerMetric as WorkerMetricProto, WorkerStatus};
1111
use proto::controller::controller_server::ControllerServer;
1212
use proto::worker::worker_server::WorkerServer;
1313
use scheduler::Event;
1414
use scheduler::{Controller, SchedulerError, Worker, WorkerRegisterChannelType};
15-
use std::default::Default;
15+
1616
use std::net::{SocketAddr, SocketAddrV4};
1717
use std::sync::Arc;
1818
use tracing::{debug, error, info, warn};

0 commit comments

Comments
 (0)