Add a logging system, using the log crate
This commit is contained in:
parent
c429d88d1b
commit
8f105eb41f
|
@ -12,3 +12,7 @@ edition = "2018"
|
|||
[dependencies]
|
||||
serde = "1.0.1"
|
||||
serde_json = "1.0.0"
|
||||
log = "0.4.6"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "*"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use log::debug;
|
||||
use serde_json::{self, Value};
|
||||
use std::collections::HashMap;
|
||||
use std::io::BufReader;
|
||||
|
@ -282,6 +283,7 @@ pub fn listen(instance: &mut Mpv) -> Result<Event, Error> {
|
|||
let mut response = String::new();
|
||||
instance.reader.read_line(&mut response).unwrap();
|
||||
response = response.trim_end().to_string();
|
||||
debug!("Event: {}", response);
|
||||
match serde_json::from_str::<Value>(&response) {
|
||||
Ok(e) => {
|
||||
if let Value::String(ref name) = e["event"] {
|
||||
|
@ -418,6 +420,7 @@ fn send_command_sync(instance: &Mpv, command: &str) -> String {
|
|||
match stream.write_all(command.as_bytes()) {
|
||||
Err(why) => panic!("Error: Could not write to socket: {}", why),
|
||||
Ok(_) => {
|
||||
debug!("Command: {}", command.trim_end());
|
||||
let mut response = String::new();
|
||||
{
|
||||
let mut reader = BufReader::new(stream);
|
||||
|
@ -426,6 +429,7 @@ fn send_command_sync(instance: &Mpv, command: &str) -> String {
|
|||
reader.read_line(&mut response).unwrap();
|
||||
}
|
||||
}
|
||||
debug!("Response: {}", response.trim_end());
|
||||
response
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue