Skip to content

Commit

Permalink
migrate to tracing fwk
Browse files Browse the repository at this point in the history
Use the tracing framework for logging purposes. It will enable us to do
better logging and tracing going forward. SimpleLogger is therefore removed.

This commit also adds hourly log-rotation to '/var/log/bmcd'
  • Loading branch information
svenrademakers committed Mar 28, 2024
1 parent 6554949 commit 515b06b
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 132 deletions.
127 changes: 93 additions & 34 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ humansize = "2.1.3"
humantime = "2.1.0"
if-addrs = "0.11.0"
inotify = "0.10.2"
log = "0.4.21"
nix = { version = "0.27.1", features = ["fs", "feature"] }
openssl = "0.10.64"
pin-project = "1.1.5"
Expand All @@ -46,7 +45,6 @@ serde_json = "1.0.114"
serde_with = "3.6.1"
serde_yaml = "0.9.32"
sha2 = "0.10.8"
simple_logger = "4.3.3"
tar = "0.4.40"
thiserror = "1.0.57"
tokio = { version = "1.36.0", features = [
Expand All @@ -60,6 +58,9 @@ tokio = { version = "1.36.0", features = [
tokio-serial = { version = "5.4.4", features = ["rt", "codec"] }
tokio-stream = { version = "0.1.14", features = ["sync"] }
tokio-util = { version = "0.7.10", features = ["io-util"] }
tracing = "0.1.40"
tracing-appender = "0.2.3"
tracing-subscriber = "0.3.18"

[dev-dependencies]
tempdir = "0.3.7"
Expand Down
20 changes: 10 additions & 10 deletions src/app/bmc_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ use crate::{
};

use anyhow::{ensure, Context};
use log::info;
use log::{debug, trace};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use std::process::Command;
use std::time::Duration;
use tokio::fs::OpenOptions;
use tokio::io::{AsyncRead, AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt};
use tracing::info;
use tracing::{debug, trace};

pub type NodeInfos = [NodeInfo; 4];

Expand Down Expand Up @@ -174,7 +174,7 @@ impl BmcApplication {
self.power_controller
.power_led(led)
.await
.unwrap_or_else(|e| log::warn!("power LED error: {:#}", e));
.unwrap_or_else(|e| tracing::warn!("power LED error: {:#}", e));

// also update the actual power state accordingly
self.power_controller
Expand Down Expand Up @@ -211,7 +211,7 @@ impl BmcApplication {
}

async fn configure_usb_internal(&self, config: UsbConfig) -> anyhow::Result<()> {
log::info!("changing usb config to {:?}", config);
tracing::info!("changing usb config to {:?}", config);
let (mode, dest, route) = match config {
UsbConfig::UsbA(device) => (UsbMode::Device, device, UsbRoute::AlternativePort),
UsbConfig::Bmc(device) => (UsbMode::Device, device, UsbRoute::Bmc),
Expand All @@ -221,7 +221,7 @@ impl BmcApplication {

if mode != UsbMode::Flash {
if let Err(e) = remove_msd_function_from_usb_gadget().await {
log::error!("{:#}", e);
tracing::error!("{:#}", e);
}
}

Expand Down Expand Up @@ -257,7 +257,7 @@ impl BmcApplication {
let blk_dev = self.node_drivers.load_as_block_device().await?;

if let Err(e) = append_msd_config_to_usb_gadget(&blk_dev).await {
log::error!("msd usb-gadget: {:#}", e);
tracing::error!("msd usb-gadget: {:#}", e);
} else {
info!("BMC-OTG: Node mass storage CDC enabled");
}
Expand All @@ -276,12 +276,12 @@ impl BmcApplication {
}

async fn reboot_into_usb(&self, node: NodeId, config: UsbConfig) -> anyhow::Result<()> {
log::info!("Powering off node {:?}...", node);
tracing::info!("Powering off node {:?}...", node);
self.activate_slot(!node.to_bitfield(), node.to_bitfield())
.await?;
self.configure_usb_internal(config).await?;

log::info!("Powering on...");
tracing::info!("Powering on...");
self.activate_slot(node.to_bitfield(), node.to_bitfield())
.await?;

Expand All @@ -301,13 +301,13 @@ impl BmcApplication {
let mut mem = OpenOptions::new().write(true).open("/dev/mem").await?;
mem.seek(std::io::SeekFrom::Start(0x0709_0108)).await?;
mem.write_u32(0x5AA5_A55A).await?;
log::warn!("system reboot into FEL");
tracing::warn!("system reboot into FEL");
}

self.power_controller
.status_led(true)
.await
.unwrap_or_else(|e| log::warn!("status_led: {:#}", e));
.unwrap_or_else(|e| tracing::warn!("status_led: {:#}", e));

Command::new("shutdown").args(["-r", "now"]).spawn()?;
Ok(())
Expand Down
Loading

0 comments on commit 515b06b

Please sign in to comment.