Skip to content

Commit c9d7438

Browse files
committed
imp(examples): add with-logger example
1 parent 47385f3 commit c9d7438

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

examples/with-logger.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2021 Developers of Pyroscope.
2+
3+
// Licensed under the Apache License, Version 2.0 <LICENSE or
4+
// https://www.apache.org/licenses/LICENSE-2.0>. This file may not be copied, modified, or distributed
5+
// except according to those terms.
6+
7+
extern crate pyroscope;
8+
9+
use log::{debug, error, info, trace, warn};
10+
11+
use pyroscope::{PyroscopeAgent, Result};
12+
13+
fn fibonacci(n: u64) -> u64 {
14+
match n {
15+
0 | 1 => 1,
16+
n => fibonacci(n - 1) + fibonacci(n - 2),
17+
}
18+
}
19+
20+
fn main() -> Result<()> {
21+
// Force rustc to display the log messages in the console.
22+
std::env::set_var("RUST_LOG", "trace");
23+
24+
// Initialize the logger.
25+
pretty_env_logger::init_timed();
26+
27+
info!("With Logger example");
28+
29+
// Create a new agent.
30+
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "example.logger").build()?;
31+
32+
// Start Agent
33+
agent.start()?;
34+
35+
let _result = fibonacci(47);
36+
37+
// Stop Agent
38+
agent.stop()?;
39+
40+
Ok(())
41+
}

0 commit comments

Comments
 (0)