Преглед изворни кода

Merge commit 'b0ea636179c771eaecfd52a02b3ad754f598c397'

Paul Lietar пре 9 година
родитељ
комит
2a5fd26998
11 измењених фајлова са 40 додато и 13 уклоњено
  1. 11 0
      Cargo.lock
  2. 3 1
      Cargo.toml
  3. 1 1
      src/audio_backend/portaudio.rs
  4. 1 1
      src/audio_backend/pulseaudio.rs
  5. 1 1
      src/audio_file.rs
  6. 3 0
      src/lib.rs
  7. 13 2
      src/main.rs
  8. 1 1
      src/mercury.rs
  9. 1 1
      src/player.rs
  10. 4 4
      src/session.rs
  11. 1 1
      src/spirc.rs

+ 11 - 0
Cargo.lock

@@ -6,6 +6,7 @@ dependencies = [
  "byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "clippy 0.0.63 (registry+https://github.com/rust-lang/crates.io-index)",
  "dns-sd 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "eventual 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
  "hyper 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -14,6 +15,7 @@ dependencies = [
  "libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)",
  "librespot-protocol 0.1.0",
  "lmdb-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "portaudio 0.2.0 (git+https://github.com/mvdnes/portaudio-rs)",
@@ -124,6 +126,15 @@ dependencies = [
  "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "env_logger"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 0.1.67 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "eventual"
 version = "0.1.6"

+ 3 - 1
Cargo.toml

@@ -33,6 +33,8 @@ rustc-serialize = "~0.3.16"
 tempfile        = "~2.0.0"
 time            = "~0.1.34"
 url             = "~0.5.2"
+log             = "0.3.5"
+env_logger      = "0.3.2"
 shannon         = { git = "https://github.com/plietar/rust-shannon" }
 
 vorbis          = "~0.0.14"
@@ -41,7 +43,7 @@ tremor          = { git = "https://github.com/plietar/rust-tremor", optional = t
 dns-sd          = { version  = "~0.1.1", optional = true }
 
 portaudio       = { git = "https://github.com/mvdnes/portaudio-rs", optional = true }
-libpulse-sys	= { git = "https://github.com/astro/libpulse-sys", optional = true }
+libpulse-sys    = { git = "https://github.com/astro/libpulse-sys", optional = true }
 
 json_macros     = { git = "https://github.com/plietar/json_macros" }
 protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros" }

+ 1 - 1
src/audio_backend/portaudio.rs

@@ -30,7 +30,7 @@ impl <'a> Sink for PortAudioSink<'a> {
     fn write(&self, data: &[i16]) -> io::Result<()> {
         match self.0.write(&data) {
             Ok(_) => (),
-            Err(portaudio::PaError::OutputUnderflowed) => eprintln!("Underflow"),
+            Err(portaudio::PaError::OutputUnderflowed) => error!("PortAudio write underflow"),
             Err(e) => panic!("PA Error {}", e),
         };
 

+ 1 - 1
src/audio_backend/pulseaudio.rs

@@ -9,7 +9,7 @@ pub struct PulseAudioSink(*mut pa_simple);
 
 impl Open for PulseAudioSink {
    fn open() -> PulseAudioSink {
-        println!("Using PulseAudioSink");
+        info!("Using PulseAudioSink");
 
         let ss = pa_sample_spec {
             format: PA_SAMPLE_S16LE,

+ 1 - 1
src/audio_file.rs

@@ -122,7 +122,7 @@ impl AudioFile {
                                 (index * CHUNK_SIZE / 4) as u32,
                                 (CHUNK_SIZE / 4) as u32);
 
-        println!("Chunk {}", index);
+        trace!("Chunk {}", index);
 
         write_file.seek(SeekFrom::Start((index * CHUNK_SIZE) as u64)).unwrap();
 

+ 3 - 0
src/lib.rs

@@ -25,6 +25,9 @@ extern crate time;
 extern crate tempfile;
 extern crate url;
 
+#[macro_use]
+extern crate log;
+
 #[cfg(not(feature = "with-tremor"))]
 extern crate vorbis;
 #[cfg(feature = "with-tremor")]

+ 13 - 2
src/main.rs

@@ -1,6 +1,9 @@
 extern crate getopts;
 extern crate librespot;
 extern crate rpassword;
+extern crate env_logger;
+#[macro_use]
+extern crate log;
 
 use rpassword::read_password;
 use std::clone::Clone;
@@ -8,6 +11,7 @@ use std::fs::File;
 use std::io::{stdout, Read, Write};
 use std::path::PathBuf;
 use std::thread;
+use std::env;
 
 use librespot::audio_backend::BACKENDS;
 use librespot::authentication::{Credentials, facebook_login, discovery_login};
@@ -30,7 +34,14 @@ static APPKEY: Option<&'static [u8]> = Some(include_bytes!(concat!(env!("CARGO_M
 static APPKEY: Option<&'static [u8]> = None;
 
 fn main() {
-    println!("librespot {} ({}). Built on {}.",
+    let rust_log = "RUST_LOG";
+    if let Err(_) = env::var(rust_log) {
+        env::set_var(rust_log, "debug")
+    }
+
+    env_logger::init().unwrap();
+
+    info!("librespot {} ({}). Built on {}.",
              version::short_sha(),
              version::commit_date(),
              version::short_now());
@@ -141,7 +152,7 @@ fn main() {
     }).or(stored_credentials)
       .or_else(|| {
         if cfg!(feature = "discovery") {
-            println!("No username provided and no stored credentials, starting discovery ...");
+            info!("No username provided and no stored credentials, starting discovery ...");
             Some(discovery_login(&session.config().device_name,
                                  session.device_id()).unwrap())
         } else {

+ 1 - 1
src/mercury.rs

@@ -207,7 +207,7 @@ impl PacketHandler for MercuryManager {
                 callback: MercuryCallback::Channel,
             }
         } else {
-            println!("Ignore seq {:?} cmd {}", seq, cmd);
+            warn!("Ignore seq {:?} cmd {}", seq, cmd);
             return;
         };
 

+ 1 - 1
src/player.rs

@@ -224,7 +224,7 @@ impl PlayerInternal {
 
                         true
                     });
-                    println!("Load Done");
+                    info!("Load Done");
                 }
                 Some(PlayerCommand::Seek(position)) => {
                     vorbis_time_seek_ms(decoder.as_mut().unwrap(), position as i64).unwrap();

+ 4 - 4
src/session.rs

@@ -95,7 +95,7 @@ impl Session {
         let aps = apresolve().unwrap();
         let ap = thread_rng().choose(&aps).expect("No APs found");
 
-        println!("Connecting to AP {}", ap);
+        info!("Connecting to AP {}", ap);
         let mut connection = PlainConnection::connect(ap).unwrap();
 
         let request = protobuf_init!(protocol::keyexchange::ClientHello::new(), {
@@ -217,7 +217,7 @@ impl Session {
                 *self.0.rx_connection.lock().unwrap() = Some(connection.clone());
                 *self.0.tx_connection.lock().unwrap() = Some(connection);
 
-                eprintln!("Authenticated !");
+                info!("Authenticated !");
 
                 let reusable_credentials = Credentials {
                     username: username,
@@ -231,11 +231,11 @@ impl Session {
             0xad => {
                 let msg: protocol::keyexchange::APLoginFailed =
                     protobuf::parse_from_bytes(&data).unwrap();
-                eprintln!("Authentication failed, {:?}", msg);
+                error!("Authentication failed, {:?}", msg);
                 Err(())
             }
             _ => {
-                println!("Unexpected message {:x}", cmd);
+                error!("Unexpected message {:x}", cmd);
                 Err(())
             }
         }

+ 1 - 1
src/spirc.rs

@@ -100,7 +100,7 @@ impl SpircManager {
             let data = pkt.payload.first().unwrap();
             let frame = protobuf::parse_from_bytes::<protocol::spirc::Frame>(data).unwrap();
 
-            println!("{:?} {} {} {} {}",
+            debug!("{:?} {} {} {} {}",
                      frame.get_typ(),
                      frame.get_device_state().get_name(),
                      frame.get_ident(),