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
26 changes: 26 additions & 0 deletions console_backend/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@ use std::{
use strum::VariantNames;

use crate::constants::{AVAILABLE_BAUDRATES, AVAILABLE_REFRESH_RATES};
use crate::log_panel::LogLevel;
use crate::types::FlowControl;
use crate::{
common_constants::{SbpLogging, Tabs},
types::Connection,
};

#[derive(Debug)]
pub struct CliLogLevel(LogLevel);

impl Deref for CliLogLevel {
type Target = LogLevel;

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

impl FromStr for CliLogLevel {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Needed a second type so I could overload the from_str (already set in py2many via EnumString) function to display available variants to the user if they mispell one.

type Err = String;

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(CliLogLevel(LogLevel::from_str(s).map_err(|_| {
format!("Must choose from available tabs {:?}", LogLevel::VARIANTS)
})?))
}
}

#[derive(Debug)]
pub struct CliTabs(Tabs);

Expand Down Expand Up @@ -73,6 +95,10 @@ pub struct CliOptions {
#[clap(long = "sbp-log")]
pub sbp_log: Option<CliSbpLogging>,

/// Set Console Log Level Filter. Default: INFO.
#[clap(long = "log-level")]
pub log_level: Option<CliLogLevel>,

/// Set log directory.
#[clap(long = "log-dirname")]
pub dirname: Option<String>,
Expand Down
23 changes: 22 additions & 1 deletion console_backend/src/common_constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
// cargo-deps: strum,strum_macros
//! ```cargo
//! [package]
//! edition = "2018"
//! [dependencies]
//! strum = "*"
//! strum_macros = "*"
//! ```

#![allow(clippy::collapsible_else_if)]
#![allow(clippy::double_parens)] // https://github.com/adsharma/py2many/issues/17
#![allow(clippy::map_identity)]
#![allow(clippy::needless_return)]
#![allow(clippy::print_literal)]
#![allow(clippy::ptr_arg)]
#![allow(clippy::redundant_static_lifetimes)] // https://github.com/adsharma/py2many/issues/266
#![allow(clippy::unnecessary_cast)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::useless_vec)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
Expand Down Expand Up @@ -178,6 +193,12 @@ pub enum Keys {
NHC,
#[strum(serialize = "ZEROVEL")]
ZEROVEL,
#[strum(serialize = "YMIN")]
YMIN,
#[strum(serialize = "YMAX")]
YMAX,
#[strum(serialize = "LOG_LEVEL")]
LOG_LEVEL,
}

#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
Expand Down
15 changes: 14 additions & 1 deletion console_backend/src/log_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ use sbp::messages::logging::MsgLog;

use capnp::message::Builder;

use crate::common_constants as cc;
use crate::types::*;
use crate::utils::serialize_capnproto_builder;

use async_logger::Writer;
use chrono::Local;
use log::{debug, error, info, warn, Record};
use log::{debug, error, info, warn, LevelFilter, Record};

pub type LogLevel = cc::LogLevel;
impl LogLevel {
pub fn level_filter(&self) -> LevelFilter {
match self {
cc::LogLevel::DEBUG => LevelFilter::Debug,
cc::LogLevel::INFO => LevelFilter::Info,
cc::LogLevel::NOTICE | cc::LogLevel::WARNING => LevelFilter::Warn,
cc::LogLevel::ERROR => LevelFilter::Error,
}
}
}

// Custom formatting of `log::Record` to account for SbpLog values
pub fn splitable_log_formatter(record: &Record) -> String {
Expand Down
22 changes: 13 additions & 9 deletions console_backend/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ use std::{
};

use crate::cli_options::*;
use crate::common_constants::LogLevel;
use crate::console_backend_capnp as m;
use crate::constants::LOG_WRITER_BUFFER_MESSAGE_COUNT;
use crate::errors::*;
use crate::log_panel::{splitable_log_formatter, LogPanelWriter};
use crate::log_panel::{splitable_log_formatter, LogLevel, LogPanelWriter};
use crate::output::{CsvLogging, SbpLogging};
use crate::types::{ClientSender, FlowControl, ServerState, SharedState};
use crate::utils::{refresh_loggingbar, refresh_navbar};
Expand Down Expand Up @@ -112,6 +111,12 @@ fn handle_cli(
if let Some(folder) = opt.dirname {
shared_state.set_logging_directory(PathBuf::from(folder));
}
let log_level = if let Some(log_level_) = opt.log_level {
(*log_level_).clone()
} else {
LogLevel::INFO
};
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);
if let Some(sbp_log) = opt.sbp_log {
Expand Down Expand Up @@ -161,8 +166,7 @@ impl Server {
};
let shared_state = SharedState::new();
let server_state = ServerState::new();
refresh_navbar(&mut client_send.clone(), shared_state.clone());
refresh_loggingbar(&mut client_send.clone(), shared_state.clone());

let logger = Logger::builder()
.buf_size(LOG_WRITER_BUFFER_MESSAGE_COUNT)
.formatter(splitable_log_formatter)
Expand All @@ -171,7 +175,6 @@ impl Server {
.unwrap();

log::set_boxed_logger(Box::new(logger)).expect("Failed to set logger");
log::set_max_level(log::LevelFilter::Info);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this to handle_cli function to set based off cli if provided.


// Handle CLI Opts.
handle_cli(
Expand All @@ -180,6 +183,8 @@ impl Server {
client_send.clone(),
shared_state.clone(),
);
refresh_navbar(&mut client_send.clone(), shared_state.clone());
refresh_loggingbar(&mut client_send.clone(), shared_state.clone());
thread::spawn(move || loop {
let buf = server_recv.recv();
if let Ok(buf) = buf {
Expand Down Expand Up @@ -316,14 +321,13 @@ impl Server {
}
m::message::LogLevelFront(Ok(cv_in)) => {
let shared_state_clone = shared_state.clone();
let mut shared_data = shared_state_clone
.lock()
.expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
let log_level = cv_in
.get_log_level()
.expect(CAP_N_PROTO_DESERIALIZATION_FAILURE);
(*shared_data).log_panel.log_level =
let log_level =
LogLevel::from_str(log_level).expect(CONVERT_TO_STR_FAILURE);
shared_state_clone.set_log_level(log_level);
refresh_navbar(&mut client_send.clone(), shared_state.clone());
}
m::message::SolutionVelocityStatusFront(Ok(cv_in)) => {
let unit = cv_in
Expand Down
14 changes: 12 additions & 2 deletions console_backend/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::common_constants::{self as cc, LogLevel, SbpLogging};
use crate::common_constants::{self as cc, SbpLogging};
use crate::constants::*;
use crate::errors::*;
use crate::formatters::*;
use crate::log_panel::LogLevel;
use crate::output::CsvLogging;
use crate::piksi_tools_constants::*;
use crate::process_messages::process_messages;
Expand Down Expand Up @@ -355,6 +356,15 @@ impl SharedState {
LOG_DIRECTORY.path()
}
}
pub fn set_log_level(&self, log_level: LogLevel) {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
(*shared_data).log_panel.log_level = log_level.clone();
log::set_max_level(log_level.level_filter());
}
pub fn log_level(&self) -> LogLevel {
let shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
(*shared_data).log_panel.log_level.clone()
}
pub fn sbp_logging(&self) -> SbpLogging {
let shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
(*shared_data).logging_bar.sbp_logging.clone()
Expand Down Expand Up @@ -508,7 +518,7 @@ pub struct LogPanelState {
impl LogPanelState {
fn new() -> LogPanelState {
LogPanelState {
log_level: LogLevel::DEBUG,
log_level: LogLevel::INFO,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions console_backend/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ pub fn refresh_navbar<P: MessageSender>(client_send: &mut P, shared_state: Share
prevous_files.set(i as u32, filename);
}

nav_bar_status.set_log_level(&shared_state.log_level().to_string());

client_send.send_data(serialize_capnproto_builder(builder));
}

Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Cython = "^0.29.21"
nuitka = "<=0.6.12.4"
psutil = "5.8.0"
qt5-applications = [{ version = "^5.15.2" }]
py2many = { git = "https://github.com/john-michaelburke/py2many", rev = "console" }
py2many = { git = "https://github.com/adsharma/py2many.git", rev = "main" }

[build-system]
requires = [
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pefile==2021.5.24; sys_platform == "win32" and python_version >= "3.5" and pytho
pkgconfig==1.5.4; python_version >= "3.3" and python_version < "4.0"
pluggy==0.13.1; python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.5"
psutil==5.8.0; (python_version >= "2.6" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
py2many @ git+https://github.com/john-michaelburke/py2many@console ; python_version >= "3.8"
py2many @ git+https://github.com/adsharma/py2many.git@main ; python_version >= "3.8"
py==1.10.0; python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.5"
pycapnp==1.1.0
pyinstaller-hooks-contrib==2021.1; python_version >= "3.5"
Expand Down
8 changes: 4 additions & 4 deletions resources/Constants/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ QtObject {
}

navBar: QtObject {
readonly property int connectionDropdownWidth: 70
readonly property int serialSelectionDropdownWidth: 90
readonly property int connectionDropdownWidth: 100
readonly property int serialSelectionDropdownWidth: 100
readonly property int dropdownHeight: 40
readonly property int buttonHeight: 40
readonly property int buttonSvgHeight: 15
readonly property int urlBarHeight: 25
readonly property int navBarMargin: 10
readonly property int plotRefreshRateDropdownWidth: 50
readonly property int serialDeviceBaudRateDropdownWidth: 90
readonly property int serialDeviceFlowControlDropdownWidth: 100
readonly property int serialDeviceFlowControlDropdownWidth: 130
readonly property int serialDeviceRefreshWidth: 30
readonly property int connectButtonWidth: 30
readonly property int connectionPauseWidth: 30
readonly property int folderButtonWidth: 30
readonly property int logLevelButtonWidth: 90
readonly property int logLevelButtonWidth: 110
readonly property color placeholderTextColor: "#CDC9C9"
readonly property int padding: 0
readonly property string connectButtonPath: "images/fontawesome/power-off-solid.svg"
Expand Down
6 changes: 3 additions & 3 deletions resources/LoggingBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Rectangle {
ToolTip.text: !checked ? "On" : "Off"
checkable: true
visible: Globals.showCsvLog
onClicked: data_model.logging_bar([csvLoggingButton.checked, sbpLoggingButton.currentText, logLevelButton.currentText], folderPathBar.editText)
onClicked: data_model.logging_bar([csvLoggingButton.checked, sbpLoggingButton.currentText], folderPathBar.editText)
}

ComboBox {
Expand All @@ -47,7 +47,7 @@ Rectangle {
model: sbp_logging_labels
ToolTip.visible: hovered
ToolTip.text: "SBP Log"
onActivated: data_model.logging_bar([csvLoggingButton.checked, sbpLoggingButton.currentText, logLevelButton.currentText], folderPathBar.editText)
onActivated: data_model.logging_bar([csvLoggingButton.checked, sbpLoggingButton.currentText], folderPathBar.editText)

background: Rectangle {
border.width: 3
Expand All @@ -68,7 +68,7 @@ Rectangle {
var text = folderPathBar.currentText;
folderPathBar.currentIndex = -1;
folderPathBar.editText = text;
data_model.logging_bar([csvLoggingButton.checked, sbpLoggingButton.currentText, logLevelButton.currentText], folderPathBar.editText);
data_model.logging_bar([csvLoggingButton.checked, sbpLoggingButton.currentText], folderPathBar.editText);
}

Text {
Expand Down
10 changes: 10 additions & 0 deletions resources/NavBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ Rectangle {
serialDeviceRefresh.visible = true;
serialDeviceBaudRate.visible = true;
serialDeviceFlowControl.visible = true;
serialDeviceFill.visible = true;
} else {
serialDevice.visible = false;
serialDeviceRefresh.visible = false;
serialDeviceBaudRate.visible = false;
serialDeviceFlowControl.visible = false;
serialDeviceFill.visible = false;
}
}

Expand Down Expand Up @@ -164,6 +166,13 @@ Rectangle {

}

Item {
id: serialDeviceFill

visible: false
Layout.fillWidth: true
}

Row {
id: tcpUrlBarPortBar

Expand Down Expand Up @@ -354,6 +363,7 @@ Rectangle {
previous_ports = navBarData.previous_ports;
previous_files = navBarData.previous_files;
connectButton.checked = navBarData.connected;
logLevelButton.currentIndex = log_level_labels.indexOf(navBarData.log_level);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Keys(str, Enum):
ZEROVEL = "ZEROVEL"
YMIN = "YMIN"
YMAX = "YMAX"
LOG_LEVEL = "LOG_LEVEL"


class ApplicationStates(str, Enum):
Expand Down
2 changes: 1 addition & 1 deletion src/main/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def receive_messages(app_, backend, messages):
NAV_BAR[Keys.PREVIOUS_HOSTS][:] = m.navBarStatus.previousHosts
NAV_BAR[Keys.PREVIOUS_PORTS][:] = m.navBarStatus.previousPorts
NAV_BAR[Keys.PREVIOUS_FILES][:] = m.navBarStatus.previousFiles
NAV_BAR[Keys.LOG_LEVEL] = m.navBarStatus.logLevel
elif m.which == Message.Union.LoggingBarStatus:
LOGGING_BAR[Keys.PREVIOUS_FOLDERS][:] = m.loggingBarStatus.previousFolders
LOGGING_BAR[Keys.CSV_LOGGING] = m.loggingBarStatus.csvLogging
Expand Down Expand Up @@ -405,7 +406,6 @@ def logging_bar(self, buttons, directory) -> None:
m.loggingBarFront = m.init(Message.Union.LoggingBarFront)
m.loggingBarFront.csvLogging = buttons[0]
m.loggingBarFront.sbpLogging = buttons[1]
m.loggingBarFront.logLevel = buttons[2]
m.loggingBarFront.directory = directory
buffer = m.to_bytes()
self.endpoint.send_message(buffer)
Expand Down
Loading