Skip to content

Commit

Permalink
Merge pull request #3254 from Bravo555/feat/2089/all-components
Browse files Browse the repository at this point in the history
Add `--log-level` to `tedge` and `c8y-remote-access-plugin`
  • Loading branch information
Bravo555 authored Nov 19, 2024
2 parents 944dce0 + 5dd8966 commit 14a8bda
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crates/core/tedge/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use c8y_remote_access_plugin::C8yRemoteAccessPluginOpt;
pub use connect::*;
use tedge_agent::AgentOpt;
use tedge_config::get_config_dir;
use tedge_config::system_services::LogConfigArgs;
use tedge_mapper::MapperOpt;
use tedge_watchdog::WatchdogOpt;
use tedge_write::bin::Args as TedgeWriteOpt;
Expand Down Expand Up @@ -50,6 +51,9 @@ pub enum TEdgeOptMulticall {
global = true,
)]
config_dir: PathBuf,

#[command(flatten)]
log_args: LogConfigArgs,
},

#[clap(flatten)]
Expand Down
17 changes: 14 additions & 3 deletions crates/core/tedge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tedge::log::MaybeFancy;
use tedge::Component;
use tedge::TEdgeOptMulticall;
use tedge_apt_plugin::AptCli;
use tedge_config::system_services::set_log_level;
use tedge_config::system_services::log_init;
use tracing::log;

#[global_allocator]
Expand Down Expand Up @@ -56,8 +56,19 @@ fn main() -> anyhow::Result<()> {
block_on(tedge_watchdog::run(opt))
}
TEdgeOptMulticall::Component(Component::TedgeWrite(opt)) => tedge_write::bin::run(opt),
TEdgeOptMulticall::Tedge { cmd, config_dir } => {
set_log_level(tracing::Level::WARN);
TEdgeOptMulticall::Tedge {
cmd,
config_dir,
log_args,
} => {
let tedge_config_location =
tedge_config::TEdgeConfigLocation::from_custom_root(&config_dir);

log_init(
"tedge",
&log_args,
&tedge_config_location.tedge_config_root_path,
)?;

let build_context = BuildContext::new(config_dir);
let cmd = cmd
Expand Down
4 changes: 4 additions & 0 deletions plugins/c8y_remote_access_plugin/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::io::stdin;
use std::io::BufRead;
use std::path::PathBuf;
use tedge_config::get_config_dir;
use tedge_config::system_services::LogConfigArgs;
use tedge_config::Path;
use tedge_config::ProfileName;
use tedge_config::TEdgeConfigLocation;
Expand Down Expand Up @@ -41,6 +42,9 @@ pub struct C8yRemoteAccessPluginOpt {
)]
config_dir: PathBuf,

#[command(flatten)]
pub log_args: LogConfigArgs,

#[arg(long)]
/// Complete the installation of c8y-remote-access-plugin by declaring the supported operation.
init: bool,
Expand Down
8 changes: 8 additions & 0 deletions plugins/c8y_remote_access_plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use miette::Context;
use miette::IntoDiagnostic;
use std::io;
use std::process::Stdio;
use tedge_config::system_services::log_init;
use tedge_config::TEdgeConfig;
use tedge_utils::file::change_user_and_group;
use tedge_utils::file::create_directory_with_user_group;
Expand Down Expand Up @@ -40,6 +41,13 @@ pub async fn run(opt: C8yRemoteAccessPluginOpt) -> miette::Result<()> {
.into_diagnostic()
.context("Reading tedge config")?;

log_init(
"c8y_remote_access_plugin",
&opt.log_args,
&config_dir.tedge_config_root_path,
)
.into_diagnostic()?;

let command = parse_arguments(opt)?;

match command {
Expand Down

0 comments on commit 14a8bda

Please sign in to comment.