Differentiate between log level/state, bump version

This commit is contained in:
Stephen Seo 2022-01-07 16:05:37 +09:00
parent 91e0dfb5b8
commit 231db34338
6 changed files with 25 additions and 17 deletions

2
Cargo.lock generated
View file

@ -1427,7 +1427,7 @@ dependencies = [
[[package]] [[package]]
name = "mpd_info_screen" name = "mpd_info_screen"
version = "0.2.8" version = "0.2.9"
dependencies = [ dependencies = [
"ggez", "ggez",
"image", "image",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "mpd_info_screen" name = "mpd_info_screen"
version = "0.2.8" version = "0.2.9"
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -9,7 +9,7 @@ counter, and the filename currently being played
# Usage # Usage
mpd_info_screen 0.2.8 mpd_info_screen 0.2.9
USAGE: USAGE:
mpd_info_screen [FLAGS] [OPTIONS] <host> [port] mpd_info_screen [FLAGS] [OPTIONS] <host> [port]

View file

@ -1,9 +1,17 @@
use std::fmt::Display; use std::fmt::Display;
use structopt::clap::arg_enum; use structopt::clap::arg_enum;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum LogState {
ERROR,
WARNING,
DEBUG,
VERBOSE,
}
arg_enum! { arg_enum! {
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
pub enum LogState { pub enum LogLevel {
ERROR, ERROR,
WARNING, WARNING,
DEBUG, 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 where
T: Display, T: Display,
{ {
if level == LogState::ERROR { if state == LogState::ERROR {
log_error(msg); log_error(msg);
} else if level == LogState::WARNING { } else if state == LogState::WARNING {
if state != LogState::ERROR { if level != LogLevel::ERROR {
log_warning(msg); log_warning(msg);
} }
} else if level == LogState::DEBUG { } else if state == LogState::DEBUG {
if state == LogState::DEBUG || state == LogState::VERBOSE { if level == LogLevel::DEBUG || level == LogLevel::VERBOSE {
log_debug(msg); log_debug(msg);
} }
} else if level == LogState::VERBOSE { } else if state == LogState::VERBOSE {
if state == LogState::VERBOSE { if level == LogLevel::VERBOSE {
log_verbose(msg); log_verbose(msg);
} }
} else { } else {

View file

@ -38,11 +38,11 @@ pub struct Opt {
#[structopt( #[structopt(
short = "l", short = "l",
long = "log-level", long = "log-level",
possible_values = &debug_log::LogState::variants(), possible_values = &debug_log::LogLevel::variants(),
default_value = "ERROR", default_value = "ERROR",
case_insensitive = true, case_insensitive = true,
)] )]
log_level: debug_log::LogState, log_level: debug_log::LogLevel,
} }
fn main() -> Result<(), String> { fn main() -> Result<(), String> {

View file

@ -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::io::{self, Read, Write};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream}; use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
use std::str::FromStr; use std::str::FromStr;
@ -65,7 +65,7 @@ pub struct MPDHandlerState {
self_thread: Option<Arc<Mutex<thread::JoinHandle<Result<(), String>>>>>, self_thread: Option<Arc<Mutex<thread::JoinHandle<Result<(), String>>>>>,
dirty_flag: Arc<AtomicBool>, dirty_flag: Arc<AtomicBool>,
pub stop_flag: Arc<AtomicBool>, pub stop_flag: Arc<AtomicBool>,
log_level: LogState, log_level: LogLevel,
} }
fn check_next_chars( fn check_next_chars(
@ -228,7 +228,7 @@ impl MPDHandler {
host: Ipv4Addr, host: Ipv4Addr,
port: u16, port: u16,
password: String, password: String,
log_level: LogState, log_level: LogLevel,
) -> Result<Self, String> { ) -> Result<Self, String> {
let stream = TcpStream::connect_timeout( let stream = TcpStream::connect_timeout(
&SocketAddr::new(IpAddr::V4(host), port), &SocketAddr::new(IpAddr::V4(host), port),