More realistic debug message

This commit is contained in:
David Tolnay 2017-05-23 12:33:11 -07:00
parent 748140492c
commit 3a2a9972ff
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -119,14 +119,34 @@ The `log` crate provides logging utilities. The `env_logger` crate configures
logging via an environment variable.
```rust
#[macro_use] extern crate log;
#[macro_use]
extern crate log;
extern crate env_logger;
#
# #[macro_use]
# extern crate error_chain;
#
# error_chain! {
# foreign_links {
# SetLogger(log::SetLoggerError);
# }
# }
fn main() {
env_logger::init().unwrap();
fn execute_query(query: &str) {
debug!("Executing query: {}", query);
debug!("this is a debug {}", "message");
// then do the thing
}
fn run() -> Result<()> {
env_logger::init()?;
execute_query("DROP TABLE students");
Ok(())
}
#
# quick_main!(run);
```
If you run this code, you'll notice that no output is printed. By default, the
@ -142,7 +162,7 @@ After running this, you'll likely see a pile of logs from cargo, as well as the
following line at the very end of the output:
```
DEBUG:main: this is a debug message
DEBUG:main: Executing query: DROP TABLE students
```
[ex-log-error]: #ex-log-error