Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit d0966e9

Browse files
Logging
1 parent 67fbb10 commit d0966e9

File tree

6 files changed

+98
-24
lines changed

6 files changed

+98
-24
lines changed

Cargo.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
[package]
2+
authors = ["The Rust Project Developers"]
23
name = "rust-playpen"
34
version = "0.1.0"
4-
authors = ["The Rust Project Developers"]
55

66
[dependencies]
7+
env_logger = "0.3.3"
8+
hyper = "0.8.1"
79
iron = "0.3.0"
8-
hyper = "0.8.1" # same version iron uses
9-
url = "1.1.1"
10-
router = "0.1.1"
11-
staticfile = "0.2.0"
1210
libc = "0.2.12"
13-
unicase = "1.4.0"
11+
log = "0.3.6"
12+
lru-cache = "0.0.7"
13+
router = "0.1.1"
1414
rustc-serialize = "0.3.19"
15-
toml = "0.1.30"
1615
serde_json = "0.7.1"
17-
lru-cache = "0.0.7"
18-
irc = { version = "0.11.3", default-features = false }
16+
staticfile = "0.2.0"
17+
toml = "0.1.30"
18+
unicase = "1.4.0"
19+
url = "1.1.1"
20+
21+
[dependencies.irc]
22+
default-features = false
23+
version = "0.11.3"

playbot.toml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,4 @@ nicks = ["playbot-rs", "playbot-rs-mini"]
55
#password = "1234"
66
server = "irc.mozilla.org"
77
#port = 6667
8-
channels = ["#rust"]
9-
10-
[[server]]
11-
nicks = ["playbot-rs"]
12-
#password = "1234"
13-
server = "irc.mozilla.org"
14-
#port = 6667
15-
channels = ["#rust-offtopic"]
8+
channels = ["#rust", "#rust-internals"]

src/bin/playbot.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
extern crate rust_playpen;
2+
3+
#[macro_use] extern crate log;
4+
extern crate env_logger;
25
extern crate irc;
36
extern crate toml;
47
extern crate hyper;
@@ -34,7 +37,7 @@ fn get_rust_versions() -> Vec<String> {
3437
let version = str::from_utf8(&output).unwrap();
3538
// Strip the trailing newline
3639
let version = String::from(version.lines().next().unwrap());
37-
println!("got {:?} Rust version: {}", channel, version);
40+
debug!("got {:?} Rust version: {}", channel, version);
3841
versions.push(version);
3942
}
4043

@@ -167,19 +170,19 @@ fn main() {{
167170
let command = &msg[self.conn.current_nickname().len()..]
168171
.trim_left_matches(|ch| ch == ',' || ch == ':')
169172
.trim();
170-
println!("<{}> {}", from, command);
173+
info!("<{}> {}", from, command);
171174
self.handle_cmd(chan, command);
172175
}
173176
}
174177

175178
/// Called when receiving a private message from `from` (via `/msg playbot-rs ...`)
176179
fn handle_privmsg(&mut self, from: &str, msg: &str) {
177-
println!("(/msg) <{}> {}", from, msg);
180+
info!("(/msg) <{}> {}", from, msg);
178181
self.handle_cmd(from, msg);
179182
}
180183

181184
fn main_loop(&mut self) {
182-
println!("playbot at your service!");
185+
info!("playbot at your service!");
183186
let cloned = self.conn.clone();
184187
for msg in cloned.iter() {
185188
let msg = match msg {
@@ -217,6 +220,8 @@ fn log_error<E: Error>(e: E) {
217220
}
218221

219222
fn main() {
223+
env_logger::init().unwrap();
224+
220225
fs::metadata("whitelist").expect("syscall whitelist file not found");
221226

222227
let bitly_key = read_bitly_token();

src/bin/playpen.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
extern crate rust_playpen;
22

33
#[macro_use] extern crate iron;
4+
#[macro_use] extern crate log;
5+
extern crate env_logger;
46
extern crate hyper;
57
extern crate staticfile;
68
extern crate router;
@@ -226,6 +228,8 @@ impl AfterMiddleware for EnablePostCors {
226228
}
227229

228230
fn main() {
231+
env_logger::init().unwrap();
232+
229233
// Make sure pygmentize is installed before starting the server
230234
Command::new("pygmentize").spawn().unwrap().kill().unwrap();
231235

@@ -241,6 +245,6 @@ fn main() {
241245
chain.link_after(EnablePostCors);
242246

243247
let addr = ("0.0.0.0", 80);
244-
println!("listening on {:?}", addr);
248+
info!("listening on {:?}", addr);
245249
Iron::new(chain).http(addr).unwrap();
246250
}

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(process_exec)]
22

3+
#[macro_use] extern crate log;
34
extern crate libc;
45
extern crate lru_cache;
56

@@ -115,12 +116,12 @@ pub fn exec(channel: ReleaseChannel,
115116
Ok(())
116117
});
117118

118-
println!("running ({:?}): {} {:?}", channel, cmd, key.args);
119+
info!("running ({:?}): {} {:?}", channel, cmd, key.args);
119120
let mut child = try!(command.spawn());
120121
try!(child.stdin.as_mut().unwrap().write_all(key.input.as_bytes()));
121122

122123
let out = try!(child.wait_with_output());
123-
println!("=> {}", out.status);
124+
info!("=> {}", out.status);
124125
cache.insert(key, (out.status.clone(), out.stdout.clone()));
125126
Ok((out.status.clone(), out.stdout.clone()))
126127
})

0 commit comments

Comments
 (0)