mirror of
https://github.com/rust-lang-nursery/rust-cookbook
synced 2025-02-16 12:18:27 +00:00
More realistic debug message
This commit is contained in:
parent
748140492c
commit
3a2a9972ff
1 changed files with 25 additions and 5 deletions
30
src/app.md
30
src/app.md
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue