Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: put logs under $FLUVIO_HOME dir #3737

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/fluvio-cluster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cli = [
"tar",
"flate2",
"fluvio-extension-common/target",
"fluvio-cli-common",
"fluvio-sc-schema/use_serde",
]

Expand Down Expand Up @@ -72,6 +73,7 @@ fluvio-future = { workspace = true }

fluvio = { workspace = true }
fluvio-extension-common = { workspace = true, features = ["installation"] }
fluvio-cli-common = { workspace = true, optional = true }
fluvio-controlplane-metadata = { workspace = true, features = ["k8",] }
fluvio-sc-schema = { workspace = true }
fluvio-types = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/fluvio-cluster/src/cli/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use fluvio_sc_schema::objects::Metadata;

use crate::{InstallationType, cli::get_installation_type};
use crate::cli::ClusterCliError;
use crate::cli::start::get_log_directory;
use crate::cli::start::default_log_directory;
use crate::start::local::{DEFAULT_DATA_DIR as DEFAULT_LOCAL_DIR, DEFAULT_METADATA_SUB_DIR};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -112,7 +112,7 @@ impl DiagnosticsOpt {

// copy logs from spu
fn copy_local_logs(&self, dest_dir: &Path) -> Result<()> {
let logs_dir = std::fs::read_dir(get_log_directory())?;
let logs_dir = std::fs::read_dir(default_log_directory())?;
println!("reading local logs from {logs_dir:?}");
for entry in logs_dir.flat_map(|it| it.ok()) {
let to = dest_dir.join(entry.file_name());
Expand Down
3 changes: 2 additions & 1 deletion crates/fluvio-cluster/src/cli/start/local.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::convert::TryInto;
use std::ops::Deref;
use semver::Version;

use fluvio::config::TlsPolicy;
Expand All @@ -19,7 +20,7 @@ pub async fn process_local(
) -> Result<(), ClusterCliError> {
let mut builder = LocalConfig::builder(platform_version);
builder
.log_dir(opt.log_dir.to_string())
.log_dir(opt.log_dir.deref())
.spu_replicas(opt.spu)
.hide_spinner(false);

Expand Down
28 changes: 16 additions & 12 deletions crates/fluvio-cluster/src/cli/start/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ops::Deref;
use std::{fmt, str::FromStr};
use std::path::PathBuf;

Expand All @@ -17,36 +18,39 @@ use tls::TlsOpt;

use crate::InstallationType;

#[cfg(target_os = "macos")]
pub fn get_log_directory() -> &'static str {
"/usr/local/var/log/fluvio"
}

#[cfg(not(target_os = "macos"))]
pub fn get_log_directory() -> &'static str {
"/tmp"
pub fn default_log_directory() -> PathBuf {
let base = fluvio_cli_common::install::fluvio_base_dir().unwrap_or(std::env::temp_dir());
base.join("log")
}

#[derive(Debug, Clone)]
pub struct DefaultLogDirectory(String);
pub struct DefaultLogDirectory(PathBuf);

impl Default for DefaultLogDirectory {
fn default() -> Self {
Self(get_log_directory().to_string())
Self(default_log_directory())
}
}

impl fmt::Display for DefaultLogDirectory {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
write!(f, "{}", self.0.display())
}
}

impl FromStr for DefaultLogDirectory {
type Err = std::io::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.to_string()))
Ok(Self(s.into()))
}
}

impl Deref for DefaultLogDirectory {
type Target = PathBuf;

fn deref(&self) -> &Self::Target {
&self.0
}
}

Expand Down
Loading