Use log crate instead of println

Allows more granular control over what gets logged to the console.
This commit is contained in:
Tor Arne Vestbø 2015-08-25 23:51:49 +02:00 committed by Marcus Thiesen
parent fcd35564df
commit e08ed545ee
7 changed files with 27 additions and 3 deletions

11
Cargo.lock generated
View file

@ -6,6 +6,7 @@ dependencies = [
"byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy 0.0.55 (registry+https://github.com/rust-lang/crates.io-index)", "clippy 0.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"dns-sd 0.1.3 (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)", "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)", "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)", "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)", "libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)",
"librespot-protocol 0.1.0", "librespot-protocol 0.1.0",
"lmdb-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lmdb-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
"portaudio 0.2.0 (git+https://github.com/mvdnes/portaudio-rs)", "portaudio 0.2.0 (git+https://github.com/mvdnes/portaudio-rs)",
@ -123,6 +125,15 @@ dependencies = [
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "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.5 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.58 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "eventual" name = "eventual"
version = "0.1.6" version = "0.1.6"

View file

@ -33,6 +33,8 @@ rustc-serialize = "~0.3.16"
tempfile = "~2.0.0" tempfile = "~2.0.0"
time = "~0.1.34" time = "~0.1.34"
url = "~0.5.2" url = "~0.5.2"
log = "0.3"
env_logger = "0.3"
shannon = { git = "https://github.com/plietar/rust-shannon" } shannon = { git = "https://github.com/plietar/rust-shannon" }
vorbis = "~0.0.14" vorbis = "~0.0.14"

View file

@ -122,7 +122,7 @@ impl AudioFile {
(index * CHUNK_SIZE / 4) as u32, (index * CHUNK_SIZE / 4) as u32,
(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(); write_file.seek(SeekFrom::Start((index * CHUNK_SIZE) as u64)).unwrap();

View file

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

View file

@ -1,6 +1,7 @@
extern crate getopts; extern crate getopts;
extern crate librespot; extern crate librespot;
extern crate rpassword; extern crate rpassword;
extern crate env_logger;
use rpassword::read_password; use rpassword::read_password;
use std::clone::Clone; use std::clone::Clone;
@ -8,6 +9,7 @@ use std::fs::File;
use std::io::{stdout, Read, Write}; use std::io::{stdout, Read, Write};
use std::path::PathBuf; use std::path::PathBuf;
use std::thread; use std::thread;
use std::env;
use librespot::audio_backend::BACKENDS; use librespot::audio_backend::BACKENDS;
use librespot::authentication::{Credentials, facebook_login, discovery_login}; use librespot::authentication::{Credentials, facebook_login, discovery_login};
@ -30,6 +32,13 @@ static APPKEY: Option<&'static [u8]> = Some(include_bytes!(concat!(env!("CARGO_M
static APPKEY: Option<&'static [u8]> = None; static APPKEY: Option<&'static [u8]> = None;
fn main() { fn main() {
let rust_log = "RUST_LOG";
if let Err(_) = env::var(rust_log) {
env::set_var(rust_log, "info")
}
env_logger::init().unwrap();
println!("librespot {} ({}). Built on {}.", println!("librespot {} ({}). Built on {}.",
version::short_sha(), version::short_sha(),
version::commit_date(), version::commit_date(),

View file

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

View file

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