Add log crate

This commit is contained in:
Patrick Auernig 2018-03-22 20:15:47 +01:00
parent f79b52f60f
commit 86fa860499
5 changed files with 26 additions and 4 deletions

View File

@ -13,6 +13,7 @@ serde = "^1.0"
serde_derive = "^1.0"
serde_json = "^1.0"
byte = "0.2"
log = "~0.4"
[dependencies.uuid]
version = "^0.6.2"
@ -21,3 +22,6 @@ features = ["v4"]
[features]
default = ["rich_presence"]
rich_presence = []
[workspace]
members = ["examples/discord_presence"]

View File

@ -0,0 +1,12 @@
[package]
authors = ["Patrick Auernig <dev.patrick.auernig@gmail.com>"]
name = "discord-presence"
version = "0.0.0"
[dependencies]
simplelog = "~0.5"
[dependencies.discord-rpc-client]
path = "../../"
version = "^0.1"
default-features = true

View File

@ -1,9 +1,13 @@
extern crate simplelog;
extern crate discord_rpc_client;
use simplelog::*;
use std::{thread, time};
use discord_rpc_client::Client as DiscordRPC;
fn main() {
TermLogger::init(LevelFilter::Debug, Config::default()).unwrap();
let mut drpc =
DiscordRPC::new(425407036495495169)
.and_then(|rpc| rpc.start())

View File

@ -54,12 +54,12 @@ impl Client {
fn send<T>(&mut self, opcode: u32, payload: T) -> Result<()>
where T: Payload + Debug
{
println!("payload: {:#?}", payload);
debug!("payload: {:#?}", payload);
match Message::new(opcode, payload).encode() {
Err(why) => println!("{:?}", why),
Err(why) => error!("{:?}", why),
Ok(bytes) => {
self.socket.write_all(bytes.as_ref())?;
println!("sent opcode: {}", opcode);
debug!("sent opcode: {}", opcode);
self.receive()?;
}
};
@ -70,7 +70,7 @@ impl Client {
fn receive(&mut self) -> Result<()> {
let mut buf: Vec<u8> = Vec::with_capacity(1024);
self.socket.read(buf.as_mut_slice())?;
println!("{:?}", buf);
debug!("{:?}", buf);
Ok(())
}
}

View File

@ -1,5 +1,7 @@
#![feature(getpid)]
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
extern crate serde;