Skip to content

Commit

Permalink
Merge pull request #7 from sync/feature/use-log-crate
Browse files Browse the repository at this point in the history
Use log trait instead of println / eprintln
  • Loading branch information
kayleg authored Jun 12, 2020
2 parents 8d0cd04 + 4cb73c3 commit 1dc79b1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ base64 = "0.11"
lazy_static = "1.4.0"
envy = "0.4"
rand = "0.7"
log = "0.4"
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ fn main() {
}
```

### Log Config

In order to produce log output, executables have to use a logger implementation compatible with the log facade.
There are many available implementations to chose from, for example:

[env_logger](https://github.com/sebasmagri/env_logger/) is an excellent way to log in your executables.

```
[dependencies]
log = "0.4"
env_logger = "0.7"
```

```
fn main() {
env_logger::init();
info!("starting up");
// ...
}
```

## Subscribing

### Connecting to existing subscription
Expand Down
3 changes: 2 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use goauth::auth::JwtClaims;
use goauth::scopes::Scope;
use hyper::client::HttpConnector;
use hyper_tls::HttpsConnector;
use log::{error, info};
use smpl_jwt::Jwt;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -105,7 +106,7 @@ impl Client {
int.tick().await;
println!("Renewing pubsub token");
if let Err(e) = client.refresh_token() {
eprintln!("Failed to update token: {}", e);
error!("Failed to update token: {}", e);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::message::{FromPubSubMessage, Message};
use bytes::buf::BufExt as _;
use hyper::{Method, StatusCode};
use lazy_static::lazy_static;
use log::error;
use serde_derive::{Deserialize, Serialize};
use std::env;

Expand Down Expand Up @@ -53,7 +54,7 @@ impl Subscription {
*req.uri_mut() = uri.clone();

if let Err(e) = client.hyper_client().request(req).await {
eprintln!("Failed ACk: {}", e);
error!("Failed ACk: {}", e);
}
}

Expand Down Expand Up @@ -98,7 +99,7 @@ impl Subscription {
.filter_map(|packet| match T::from(packet.message) {
Ok(o) => Some(o),
Err(e) => {
eprintln!("Failed converting pubsub {}", e,);
error!("Failed converting pubsub {}", e,);
None
}
})
Expand Down

0 comments on commit 1dc79b1

Please sign in to comment.