Skip to content
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
2 changes: 1 addition & 1 deletion console_backend/src/baseline_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl<S: CapnProtoSender> BaselineTab<S> {
flags: baseline_ned_fields.flags,
num_sats: baseline_ned_fields.n_sats,
}) {
eprintln!("Unable to to write to baseline log, error {}.", err);
error!("Unable to to write to baseline log, error {}.", err);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion console_backend/src/bin/headless-console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Usage:
let (_server_send, server_recv) = channel::unbounded::<Vec<u8>>();
let client_send = ClientSender::new(client_send_);
let shared_state = SharedState::new();
setup_logging(client_send.clone(), shared_state.clone(), true);
setup_logging(client_send.clone(), shared_state.clone());
let conn_manager = ConnectionManager::new(client_send.clone(), shared_state.clone());
handle_cli(opt, &conn_manager, shared_state.clone());
refresh_connection_frontend(&mut client_send.clone(), shared_state.clone());
Expand Down
9 changes: 7 additions & 2 deletions console_backend/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ pub struct CliOptions {
#[clap(subcommand)]
pub input: Option<Input>,

/// Log messages to terminal.
#[clap(long = "log-stderr")]
pub log_stderr: bool,

/// Exit when connection closes.
#[clap(long = "exit-after")]
pub exit_after: bool,
Expand Down Expand Up @@ -150,7 +154,7 @@ impl CliOptions {
/// - `filtered_args`: The filtered args parsed via CliOptions.
pub fn from_filtered_cli() -> CliOptions {
let args = std::env::args();
debug!("args {:?}", args);
eprintln!("args {:?}", args);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed overkill to have this and filtered args display in the console log so this only goes to standard error.

let mut next_args = std::env::args().skip(1);
let mut filtered_args: Vec<String> = vec![];
for arg in args.filter(|a| !matches!(a.as_str(), "swiftnav_console.main" | "-m" | "--")) {
Expand All @@ -168,7 +172,7 @@ impl CliOptions {
}
filtered_args.push(arg);
}
debug!("filtered_args: {:?}", filtered_args);
debug!("filtered_args: {:?}", &filtered_args[1..]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the first argument which equates to the python3 to only show arguments passed to console.

CliOptions::parse_from(filtered_args)
}
}
Expand Down Expand Up @@ -306,6 +310,7 @@ pub fn handle_cli(opt: CliOptions, conn_manager: &ConnectionManager, shared_stat
shared_state.set_log_level(log_level);
let mut shared_data = shared_state.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
(*shared_data).logging_bar.csv_logging = CsvLogging::from(opt.csv_log);
(*shared_data).log_to_std.set(opt.log_stderr);
if let Some(sbp_log) = opt.sbp_log {
(*shared_data).logging_bar.sbp_logging_format =
SbpLogging::from_str(&sbp_log.to_string()).expect(CONVERT_TO_STR_FAILURE);
Expand Down
23 changes: 13 additions & 10 deletions console_backend/src/log_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::common_constants as cc;
use crate::constants::LOG_WRITER_BUFFER_MESSAGE_COUNT;
use crate::errors::CONSOLE_LOG_JSON_TO_STRING_FAILURE;
use crate::shared_state::SharedState;
use crate::types::{CapnProtoSender, ClientSender};
use crate::types::{ArcBool, CapnProtoSender, ClientSender};
use crate::utils::serialize_capnproto_builder;

use async_logger::Writer;
Expand Down Expand Up @@ -44,7 +44,7 @@ pub fn splitable_log_formatter(record: &Record) -> String {
} else {
record.level().as_str()
};
let timestamp = Local::now().format("%Y-%m-%dT%H:%M:%S");
let timestamp = Local::now().format("%b %d %Y %H:%M:%S");
let mut msg = record.args().to_string();
msg.retain(|c| c != '\0');
let msg_packet = ConsoleLogPacket {
Expand Down Expand Up @@ -97,8 +97,8 @@ pub fn handle_log_msg(msg: MsgLog) {
}
}

pub fn setup_logging(client_sender: ClientSender, shared_state: SharedState, debug: bool) {
let log_panel = LogPanelWriter::new(client_sender, shared_state, debug);
pub fn setup_logging(client_sender: ClientSender, shared_state: SharedState) {
let log_panel = LogPanelWriter::new(client_sender, shared_state);
let logger = Logger::builder()
.buf_size(LOG_WRITER_BUFFER_MESSAGE_COUNT)
.formatter(splitable_log_formatter)
Expand All @@ -107,21 +107,22 @@ pub fn setup_logging(client_sender: ClientSender, shared_state: SharedState, deb
.unwrap();

log::set_boxed_logger(Box::new(logger)).expect("Failed to set logger");
log::set_max_level(LevelFilter::Debug);
}

#[derive(Debug)]
pub struct LogPanelWriter<S: CapnProtoSender> {
pub client_sender: S,
shared_state: SharedState,
pub debug: bool,
pub log_to_std: ArcBool,
}

impl<S: CapnProtoSender> LogPanelWriter<S> {
pub fn new(client_sender: S, shared_state: SharedState, debug: bool) -> LogPanelWriter<S> {
pub fn new(client_sender: S, shared_state: SharedState) -> LogPanelWriter<S> {
LogPanelWriter {
client_sender,
log_to_std: shared_state.log_to_std(),
shared_state,
debug,
}
}
}
Expand All @@ -140,12 +141,14 @@ impl<S: CapnProtoSender> Writer<Box<String>> for LogPanelWriter<S> {
let mut entries = log_update.init_entries(slice.len() as u32);

for (idx, item) in slice.iter().enumerate() {
if self.debug {
eprintln!("{}", item);
let packet: ConsoleLogPacket =
serde_json::from_str(item).expect(CONSOLE_LOG_JSON_TO_STRING_FAILURE);
if self.log_to_std.get() {
eprintln!("{}\t{}\t{}", packet.timestamp, packet.level, packet.msg);
}
let mut entry = entries.reborrow().get(idx as u32);

entry.set_line(&**item);
entry.set_line(item);
}

self.client_sender
Expand Down
2 changes: 1 addition & 1 deletion console_backend/src/process_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ where
});

link.register(|_: MsgObsDepA| {
println!("The message type, MsgObsDepA, is not handled in the Tracking->SignalsPlot or Observation tab.");
debug!("The message type, MsgObsDepA, is not handled in the Tracking->SignalsPlot or Observation tab.");
});

link.register(|tabs: &Tabs<S>, msg: MsgOrientEuler| {
Expand Down
2 changes: 1 addition & 1 deletion console_backend/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Server {
server_send: Some(server_send),
};
let shared_state = SharedState::new();
setup_logging(client_send.clone(), shared_state.clone(), false);
setup_logging(client_send.clone(), shared_state.clone());
let opt = CliOptions::from_filtered_cli();
if let Some(ref path) = opt.settings_yaml {
sbp_settings::settings::load_from_path(path).expect("failed to load settings");
Expand Down
4 changes: 2 additions & 2 deletions console_backend/src/server_recv_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::utils::refresh_connection_frontend;
use capnp::serialize;
use chrono::{DateTime, Utc};
use crossbeam::channel;
use log::error;
use log::{debug, error};
use std::{io::Cursor, path::PathBuf, str::FromStr, thread};
pub type Error = anyhow::Error;
pub type Result<T> = anyhow::Result<T>;
Expand Down Expand Up @@ -334,7 +334,7 @@ pub fn server_recv_thread(
}
}
}
eprintln!("client recv loop shutdown");
debug!("client recv loop shutdown");
client_send.connected.set(false);
});
}
8 changes: 7 additions & 1 deletion console_backend/src/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::output::{CsvLogging, CsvSerializer};
use crate::process_messages::StopToken;
use crate::settings_tab;
use crate::solution_tab::LatLonUnits;
use crate::types::CapnProtoSender;
use crate::types::{ArcBool, CapnProtoSender};
use crate::update_tab::UpdateTabUpdate;
use crate::utils::send_conn_state;
use crate::watch::{WatchReceiver, Watched};
Expand Down Expand Up @@ -356,6 +356,10 @@ impl SharedState {
(*shared_data).auto_survey_data.alt = Some(alt);
(*shared_data).auto_survey_data.requested = false;
}
pub fn log_to_std(&self) -> ArcBool {
let shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
(*shared_data).log_to_std.clone()
}
}

impl Deref for SharedState {
Expand Down Expand Up @@ -401,6 +405,7 @@ pub struct SharedStateInner {
pub(crate) advanced_networking_update: Option<AdvancedNetworkingState>,
pub(crate) auto_survey_data: AutoSurveyData,
pub(crate) sbp_logging_stats_state: Option<SbpLoggingStatsState>,
pub(crate) log_to_std: ArcBool,
}
impl SharedStateInner {
pub fn new() -> SharedStateInner {
Expand All @@ -427,6 +432,7 @@ impl SharedStateInner {
advanced_networking_update: None,
auto_survey_data: AutoSurveyData::new(),
sbp_logging_stats_state: None,
log_to_std: ArcBool::new_with(true),
Copy link
Collaborator Author

@john-michaelburke john-michaelburke Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start with true so the initial "args" will go to the terminal. Then once the command line options are parsed, if log-to-std is not enabled it will switch back to false.
Screen Shot 2021-10-19 at 11 26 44 AM
.

}
}
}
Expand Down
6 changes: 3 additions & 3 deletions console_backend/src/solution_tab.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use capnp::message::Builder;

use log::error;
use sbp::messages::{
navigation::{MsgAgeCorrections, MsgPosLlhCov, MsgUtcTime},
orientation::{MsgAngularRate, MsgOrientEuler},
Expand Down Expand Up @@ -360,7 +360,7 @@ impl<S: CapnProtoSender> SolutionTab<S> {
flags: vel_ned_fields.flags,
num_signals: vel_ned_fields.n_sats,
}) {
eprintln!("Unable to to write to vel log, error {}.", err);
error!("Unable to to write to vel log, error {}.", err);
}
}
}
Expand Down Expand Up @@ -532,7 +532,7 @@ impl<S: CapnProtoSender> SolutionTab<S> {
n_sats: pos_llh_fields.n_sats,
flags: pos_llh_fields.flags,
}) {
eprintln!("Unable to to write to pos llh log, error {}.", err);
error!("Unable to to write to pos llh log, error {}.", err);
}
}
}
Expand Down