aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-10-14 22:41:25 +0200
committeracdenisSK <[email protected]>2017-10-14 22:41:25 +0200
commitcae014758a1d1e926a71679f02e32601c57f8d52 (patch)
tree39270dbc2df916a91c3c4272600fd082a2604516 /examples
parentSwitch to parking_lot::{Mutex, RwLock} (diff)
parentRelease v0.4.1 (diff)
downloadserenity-cae014758a1d1e926a71679f02e32601c57f8d52.tar.xz
serenity-cae014758a1d1e926a71679f02e32601c57f8d52.zip
Update to account for changes made in 0.4.1
Diffstat (limited to 'examples')
-rw-r--r--examples/08_env_logging/Cargo.toml12
-rw-r--r--examples/08_env_logging/src/main.rs45
2 files changed, 57 insertions, 0 deletions
diff --git a/examples/08_env_logging/Cargo.toml b/examples/08_env_logging/Cargo.toml
new file mode 100644
index 0000000..a17d55e
--- /dev/null
+++ b/examples/08_env_logging/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "08_env_logging"
+version = "0.1.0"
+authors = ["my name <[email protected]>"]
+
+[dependencies]
+env_logger = "~0.4"
+log = "~0.3"
+
+[dependencies.serenity]
+features = ["client"]
+path = "../../"
diff --git a/examples/08_env_logging/src/main.rs b/examples/08_env_logging/src/main.rs
new file mode 100644
index 0000000..db34037
--- /dev/null
+++ b/examples/08_env_logging/src/main.rs
@@ -0,0 +1,45 @@
+#[macro_use] extern crate log;
+
+extern crate env_logger;
+extern crate serenity;
+
+use serenity::prelude::*;
+use serenity::model::event::ResumedEvent;
+use serenity::model::Ready;
+use std::env;
+
+struct Handler;
+
+impl EventHandler for Handler {
+ fn on_ready(&self, _: Context, ready: Ready) {
+ // Log at the INFO level. This is a macro from the `log` crate.
+ info!("{} is connected!", ready.user.name);
+ }
+
+ fn on_resume(&self, _: Context, resume: ResumedEvent) {
+ // Log at the DEBUG level.
+ //
+ // In this example, this will not show up in the logs because DEBUG is
+ // below INFO, which is the set debug level.
+ debug!("Resumed; trace: {:?}", resume.trace);
+ }
+}
+
+fn main() {
+ // Call env_logger's initialize function, which configures `log` via
+ // environment variables.
+ //
+ // For example, you can say to log all levels INFO and up via setting the
+ // environment variable `RUST_LOG` to `INFO`.
+ env_logger::init().expect("Unable to init env_logger");
+
+ // Configure the client with your Discord bot token in the environment.
+ let token = env::var("DISCORD_TOKEN")
+ .expect("Expected a token in the environment");
+
+ let mut client = Client::new(&token, Handler);
+
+ if let Err(why) = client.start() {
+ error!("Client error: {:?}", why);
+ }
+}