-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp(examples): add with-logger example
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2021 Developers of Pyroscope. | ||
|
||
// Licensed under the Apache License, Version 2.0 <LICENSE or | ||
// https://www.apache.org/licenses/LICENSE-2.0>. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
extern crate pyroscope; | ||
|
||
use log::{debug, error, info, trace, warn}; | ||
|
||
use pyroscope::{PyroscopeAgent, Result}; | ||
|
||
fn fibonacci(n: u64) -> u64 { | ||
match n { | ||
0 | 1 => 1, | ||
n => fibonacci(n - 1) + fibonacci(n - 2), | ||
} | ||
} | ||
|
||
fn main() -> Result<()> { | ||
// Force rustc to display the log messages in the console. | ||
std::env::set_var("RUST_LOG", "trace"); | ||
|
||
// Initialize the logger. | ||
pretty_env_logger::init_timed(); | ||
|
||
info!("With Logger example"); | ||
|
||
// Create a new agent. | ||
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "example.logger").build()?; | ||
|
||
// Start Agent | ||
agent.start()?; | ||
|
||
let _result = fibonacci(47); | ||
|
||
// Stop Agent | ||
agent.stop()?; | ||
|
||
Ok(()) | ||
} |