Add a logging system, using the log crate

This commit is contained in:
Emmanuel Gil Peyrot 2019-06-18 18:34:23 +02:00
parent c429d88d1b
commit 8f105eb41f
2 changed files with 8 additions and 0 deletions

View File

@ -12,3 +12,7 @@ edition = "2018"
[dependencies]
serde = "1.0.1"
serde_json = "1.0.0"
log = "0.4.6"
[dev-dependencies]
env_logger = "*"

View File

@ -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
}
}