From 8f105eb41f9b831cdb964ba9a4f39f01b4702004 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Tue, 18 Jun 2019 18:34:23 +0200
Subject: [PATCH] Add a logging system, using the log crate

---
 Cargo.toml | 4 ++++
 src/ipc.rs | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/Cargo.toml b/Cargo.toml
index e4e0ca3..c1500ad 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,3 +12,7 @@ edition = "2018"
 [dependencies]
 serde = "1.0.1"
 serde_json = "1.0.0"
+log = "0.4.6"
+
+[dev-dependencies]
+env_logger = "*"
diff --git a/src/ipc.rs b/src/ipc.rs
index a90a608..7b7d93f 100644
--- a/src/ipc.rs
+++ b/src/ipc.rs
@@ -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
         }
     }