Differentiate between log level/state, bump version
This commit is contained in:
parent
91e0dfb5b8
commit
231db34338
6 changed files with 25 additions and 17 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1427,7 +1427,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "mpd_info_screen"
|
||||
version = "0.2.8"
|
||||
version = "0.2.9"
|
||||
dependencies = [
|
||||
"ggez",
|
||||
"image",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "mpd_info_screen"
|
||||
version = "0.2.8"
|
||||
version = "0.2.9"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -9,7 +9,7 @@ counter, and the filename currently being played
|
|||
|
||||
# Usage
|
||||
|
||||
mpd_info_screen 0.2.8
|
||||
mpd_info_screen 0.2.9
|
||||
|
||||
USAGE:
|
||||
mpd_info_screen [FLAGS] [OPTIONS] <host> [port]
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
use std::fmt::Display;
|
||||
use structopt::clap::arg_enum;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum LogState {
|
||||
ERROR,
|
||||
WARNING,
|
||||
DEBUG,
|
||||
VERBOSE,
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum LogState {
|
||||
pub enum LogLevel {
|
||||
ERROR,
|
||||
WARNING,
|
||||
DEBUG,
|
||||
|
@ -11,22 +19,22 @@ arg_enum! {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn log<T>(msg: T, level: LogState, state: LogState)
|
||||
pub fn log<T>(msg: T, state: LogState, level: LogLevel)
|
||||
where
|
||||
T: Display,
|
||||
{
|
||||
if level == LogState::ERROR {
|
||||
if state == LogState::ERROR {
|
||||
log_error(msg);
|
||||
} else if level == LogState::WARNING {
|
||||
if state != LogState::ERROR {
|
||||
} else if state == LogState::WARNING {
|
||||
if level != LogLevel::ERROR {
|
||||
log_warning(msg);
|
||||
}
|
||||
} else if level == LogState::DEBUG {
|
||||
if state == LogState::DEBUG || state == LogState::VERBOSE {
|
||||
} else if state == LogState::DEBUG {
|
||||
if level == LogLevel::DEBUG || level == LogLevel::VERBOSE {
|
||||
log_debug(msg);
|
||||
}
|
||||
} else if level == LogState::VERBOSE {
|
||||
if state == LogState::VERBOSE {
|
||||
} else if state == LogState::VERBOSE {
|
||||
if level == LogLevel::VERBOSE {
|
||||
log_verbose(msg);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -38,11 +38,11 @@ pub struct Opt {
|
|||
#[structopt(
|
||||
short = "l",
|
||||
long = "log-level",
|
||||
possible_values = &debug_log::LogState::variants(),
|
||||
possible_values = &debug_log::LogLevel::variants(),
|
||||
default_value = "ERROR",
|
||||
case_insensitive = true,
|
||||
)]
|
||||
log_level: debug_log::LogState,
|
||||
log_level: debug_log::LogLevel,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), String> {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::debug_log::{log, LogState};
|
||||
use crate::debug_log::{log, LogLevel, LogState};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
|
||||
use std::str::FromStr;
|
||||
|
@ -65,7 +65,7 @@ pub struct MPDHandlerState {
|
|||
self_thread: Option<Arc<Mutex<thread::JoinHandle<Result<(), String>>>>>,
|
||||
dirty_flag: Arc<AtomicBool>,
|
||||
pub stop_flag: Arc<AtomicBool>,
|
||||
log_level: LogState,
|
||||
log_level: LogLevel,
|
||||
}
|
||||
|
||||
fn check_next_chars(
|
||||
|
@ -228,7 +228,7 @@ impl MPDHandler {
|
|||
host: Ipv4Addr,
|
||||
port: u16,
|
||||
password: String,
|
||||
log_level: LogState,
|
||||
log_level: LogLevel,
|
||||
) -> Result<Self, String> {
|
||||
let stream = TcpStream::connect_timeout(
|
||||
&SocketAddr::new(IpAddr::V4(host), port),
|
||||
|
|
Loading…
Reference in a new issue