Skip to content

Commit 4cb73c3

Browse files
committed
Use log trait instead of println / eprintln
1 parent 8d0cd04 commit 4cb73c3

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ base64 = "0.11"
2424
lazy_static = "1.4.0"
2525
envy = "0.4"
2626
rand = "0.7"
27+
log = "0.4"

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ fn main() {
5555
}
5656
```
5757

58+
### Log Config
59+
60+
In order to produce log output, executables have to use a logger implementation compatible with the log facade.
61+
There are many available implementations to chose from, for example:
62+
63+
[env_logger](https://github.com/sebasmagri/env_logger/) is an excellent way to log in your executables.
64+
65+
```
66+
[dependencies]
67+
log = "0.4"
68+
env_logger = "0.7"
69+
```
70+
71+
```
72+
fn main() {
73+
env_logger::init();
74+
75+
info!("starting up");
76+
77+
// ...
78+
}
79+
```
80+
5881
## Subscribing
5982

6083
### Connecting to existing subscription

src/client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use goauth::auth::JwtClaims;
55
use goauth::scopes::Scope;
66
use hyper::client::HttpConnector;
77
use hyper_tls::HttpsConnector;
8+
use log::{error, info};
89
use smpl_jwt::Jwt;
910
use std::sync::atomic::{AtomicBool, Ordering};
1011
use std::sync::{Arc, RwLock};
@@ -105,7 +106,7 @@ impl Client {
105106
int.tick().await;
106107
println!("Renewing pubsub token");
107108
if let Err(e) = client.refresh_token() {
108-
eprintln!("Failed to update token: {}", e);
109+
error!("Failed to update token: {}", e);
109110
}
110111
}
111112
}

src/subscription.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::message::{FromPubSubMessage, Message};
44
use bytes::buf::BufExt as _;
55
use hyper::{Method, StatusCode};
66
use lazy_static::lazy_static;
7+
use log::error;
78
use serde_derive::{Deserialize, Serialize};
89
use std::env;
910

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

5556
if let Err(e) = client.hyper_client().request(req).await {
56-
eprintln!("Failed ACk: {}", e);
57+
error!("Failed ACk: {}", e);
5758
}
5859
}
5960

@@ -98,7 +99,7 @@ impl Subscription {
9899
.filter_map(|packet| match T::from(packet.message) {
99100
Ok(o) => Some(o),
100101
Err(e) => {
101-
eprintln!("Failed converting pubsub {}", e,);
102+
error!("Failed converting pubsub {}", e,);
102103
None
103104
}
104105
})

0 commit comments

Comments
 (0)