Skip to content

Commit 4d7f00b

Browse files
committed
feat(log): change packet log to core file log
1 parent bdb7d66 commit 4d7f00b

1 file changed

Lines changed: 16 additions & 28 deletions

File tree

src/main.rs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use rattan_core::{
3333
};
3434
use serde::{Deserialize, Serialize};
3535
use tracing::{debug, error, info, warn};
36-
use tracing_subscriber::filter::{self, FilterFn};
3736
use tracing_subscriber::Layer;
3837
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
3938

@@ -129,14 +128,14 @@ pub struct Arguments {
129128
#[arg(long, global = true, value_name = "JSON", requires = "downlink-queue")]
130129
downlink_queue_args: Option<String>,
131130

132-
/// Enable packet logging
131+
/// Enable logging to file
133132
#[arg(long)]
134-
packet_log: bool,
135-
// This "requires" field uses an underscore '_' instead of a dash '-' since "packet_log" is a
133+
file_log: bool,
134+
// This "requires" field uses an underscore '_' instead of a dash '-' since "file_log" is a
136135
// field name instead of a group name
137-
/// Packet log path, default to $CACHE_DIR/rattan/packet.log
138-
#[arg(long, value_name = "Log File", requires = "packet_log")]
139-
packet_log_path: Option<String>,
136+
/// File log path, default to $CACHE_DIR/rattan/core.log
137+
#[arg(long, value_name = "Log File", requires = "file_log")]
138+
file_log_path: Option<String>,
140139

141140
/// Command to run in left ns. Only used when in isolated mode
142141
#[arg(long = "left", num_args = 0..)]
@@ -283,19 +282,13 @@ fn main() -> ExitCode {
283282
// }
284283

285284
// Install Tracing Subscriber
286-
let subscriber = tracing_subscriber::registry().with(
287-
tracing_subscriber::fmt::layer()
288-
.with_filter(
289-
tracing_subscriber::EnvFilter::try_from_default_env()
290-
.unwrap_or_else(|_| "warn".into()),
291-
)
292-
.with_filter(filter::filter_fn(|metadata| {
293-
!metadata.target().ends_with("packet")
294-
})),
295-
);
296-
let _guard: Option<_> = if opts.packet_log {
285+
let subscriber =
286+
tracing_subscriber::registry().with(tracing_subscriber::fmt::layer().with_filter(
287+
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "warn".into()),
288+
));
289+
let _guard: Option<_> = if opts.file_log {
297290
if let Some((log_dir, file_name)) = opts
298-
.packet_log_path
291+
.file_log_path
299292
.and_then(|path| {
300293
let path = std::path::PathBuf::from(path);
301294
let file_name = path.file_name().and_then(|f| f.to_str());
@@ -311,7 +304,7 @@ fn main() -> ExitCode {
311304
p.push("rattan");
312305
p
313306
})
314-
.map(|log_dir| (log_dir, "packet.log".to_string()))
307+
.map(|log_dir| (log_dir, "core.log".to_string()))
315308
})
316309
{
317310
if let Err(e) = std::fs::create_dir_all(&log_dir) {
@@ -331,17 +324,12 @@ fn main() -> ExitCode {
331324
};
332325
// let file_logger = tracing_appender::rolling::daily(log_dir, file_name_prefix);
333326
let (non_blocking, guard) = tracing_appender::non_blocking(file_logger);
334-
let file_log_filter = FilterFn::new(|metadata| {
335-
// Only enable spans or events with the target "interesting_things"
336-
metadata.target().ends_with("::packet_log")
337-
});
338-
let env_filter = tracing_subscriber::EnvFilter::try_from_env("RATTAN_PACKET_LOG")
339-
.unwrap_or_else(|_| "trace".into());
327+
let env_filter = tracing_subscriber::EnvFilter::try_from_env("RATTAN_LOG")
328+
.unwrap_or_else(|_| "info".into());
340329
subscriber
341330
.with(
342331
tracing_subscriber::fmt::layer()
343332
.with_writer(non_blocking)
344-
.with_filter(file_log_filter)
345333
.with_filter(env_filter),
346334
)
347335
.init();
@@ -683,7 +671,7 @@ fn main() -> ExitCode {
683671
client_handle.args(arguments);
684672
} else {
685673
client_handle.arg(opts.shell.shell().as_ref());
686-
if matches!(opts.shell, TaskShell::Bash) {
674+
if opts.shell.shell().ends_with("/bash") {
687675
client_handle
688676
.env("PROMPT_COMMAND", "PS1=\"[rattan] $PS1\" PROMPT_COMMAND=");
689677
}

0 commit comments

Comments
 (0)