Skip to content

Commit

Permalink
imp(examples): add with-logger example
Browse files Browse the repository at this point in the history
  • Loading branch information
omarabid committed Jan 20, 2022
1 parent 47385f3 commit c9d7438
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/with-logger.rs
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(())
}

0 comments on commit c9d7438

Please sign in to comment.