Skip to content

Commit e9b3f7c

Browse files
committed
reafactor: introduce LOG_TAG
1 parent 055576f commit e9b3f7c

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
//! agent.stop();
2525
//! ```
2626
27+
pub(crate) static LOG_TAG: &str = "pyroscope";
28+
2729
// Re-exports structs
2830
pub use crate::pyroscope::PyroscopeAgent;
2931
pub use error::{PyroscopeError, Result};

src/pyroscope.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use std::{
77
thread::JoinHandle,
88
};
99

10+
// Licensed under the Apache License, Version 2.0 <LICENSE or
11+
// https://www.apache.org/licenses/LICENSE-2.0>. This file may not be copied, modified, or distributed
12+
// except according to those terms.
1013
use crate::{
1114
backends::{pprof::Pprof, Backend},
1215
error::Result,
@@ -175,15 +178,15 @@ impl PyroscopeAgentBuilder {
175178
// Initiliaze the backend
176179
let backend = Arc::clone(&self.backend);
177180
backend.lock()?.initialize(self.config.sample_rate)?;
178-
log::trace!("PyroscopeAgent - Backend initialized");
181+
log::trace!(target: LOG_TAG, "Backend initialized");
179182

180183
// Start Timer
181184
let timer = Timer::default().initialize()?;
182-
log::trace!("PyroscopeAgent - Timer initialized");
185+
log::trace!(target: LOG_TAG, "Timer initialized");
183186

184187
// Start the SessionManager
185188
let session_manager = SessionManager::new()?;
186-
log::trace!("PyroscopeAgent - SessionManager initialized");
189+
log::trace!(target: LOG_TAG, "SessionManager initialized");
187190

188191
// Return PyroscopeAgent
189192
Ok(PyroscopeAgent {
@@ -217,44 +220,44 @@ pub struct PyroscopeAgent {
217220
impl Drop for PyroscopeAgent {
218221
/// Properly shutdown the agent.
219222
fn drop(&mut self) {
220-
log::debug!("PyroscopeAgent - Dropping Agent");
223+
log::debug!(target: LOG_TAG, "Dropping Agent");
221224

222225
// Drop Timer listeners
223226
match self.timer.drop_listeners() {
224-
Ok(_) => log::trace!("PyroscopeAgent - Dropped timer listeners"),
225-
Err(_) => log::error!("PyroscopeAgent - Error Dropping timer listeners"),
227+
Ok(_) => log::trace!(target: LOG_TAG, "Dropped timer listeners"),
228+
Err(_) => log::error!(target: LOG_TAG, "Error Dropping timer listeners"),
226229
}
227230

228231
// Wait for the Timer thread to finish
229232
if let Some(handle) = self.timer.handle.take() {
230233
match handle.join() {
231-
Ok(_) => log::trace!("PyroscopeAgent - Dropped timer thread"),
232-
Err(_) => log::error!("PyroscopeAgent - Error Dropping timer thread"),
234+
Ok(_) => log::trace!(target: LOG_TAG, "Dropped timer thread"),
235+
Err(_) => log::error!(target: LOG_TAG, "Error Dropping timer thread"),
233236
}
234237
}
235238

236239
// Stop the SessionManager
237240
match self.session_manager.push(SessionSignal::Kill) {
238-
Ok(_) => log::trace!("PyroscopeAgent - Sent kill signal to SessionManager"),
239-
Err(_) => log::error!("PyroscopeAgent - Error sending kill signal to SessionManager"),
241+
Ok(_) => log::trace!(target: LOG_TAG, "Sent kill signal to SessionManager"),
242+
Err(_) => log::error!(target: LOG_TAG, "Error sending kill signal to SessionManager"),
240243
}
241244

242245
if let Some(handle) = self.session_manager.handle.take() {
243246
match handle.join() {
244-
Ok(_) => log::trace!("PyroscopeAgent - Dropped SessionManager thread"),
245-
Err(_) => log::error!("PyroscopeAgent - Error Dropping SessionManager thread"),
247+
Ok(_) => log::trace!(target: LOG_TAG, "Dropped SessionManager thread"),
248+
Err(_) => log::error!(target: LOG_TAG, "Error Dropping SessionManager thread"),
246249
}
247250
}
248251

249252
// Wait for main thread to finish
250253
if let Some(handle) = self.handle.take() {
251254
match handle.join() {
252-
Ok(_) => log::trace!("PyroscopeAgent - Dropped main thread"),
253-
Err(_) => log::error!("PyroscopeAgent - Error Dropping main thread"),
255+
Ok(_) => log::trace!(target: LOG_TAG, "Dropped main thread"),
256+
Err(_) => log::error!(target: LOG_TAG, "Error Dropping main thread"),
254257
}
255258
}
256259

257-
log::debug!("PyroscopeAgent - Agent Dropped");
260+
log::debug!(target: LOG_TAG, "Agent Dropped");
258261
}
259262
}
260263

@@ -271,7 +274,7 @@ impl PyroscopeAgent {
271274
}
272275

273276
fn _start(&mut self) -> Result<()> {
274-
log::debug!("PyroscopeAgent - Starting");
277+
log::debug!(target: LOG_TAG, "Starting");
275278

276279
// Create a clone of Backend
277280
let backend = Arc::clone(&self.backend);
@@ -294,10 +297,10 @@ impl PyroscopeAgent {
294297
let stx = self.session_manager.tx.clone();
295298

296299
self.handle = Some(std::thread::spawn(move || {
297-
log::trace!("PyroscopeAgent - Main Thread started");
300+
log::trace!(target: LOG_TAG, "Main Thread started");
298301

299302
while let Ok(until) = rx.recv() {
300-
log::trace!("PyroscopeAgent - Sending session {}", until);
303+
log::trace!(target: LOG_TAG, "Sending session {}", until);
301304

302305
// Generate report from backend
303306
let report = backend.lock()?.report()?;
@@ -310,7 +313,7 @@ impl PyroscopeAgent {
310313
)?))?;
311314

312315
if until == 0 {
313-
log::trace!("PyroscopeAgent - Session Killed");
316+
log::trace!(target: LOG_TAG, "Session Killed");
314317

315318
let (lock, cvar) = &*pair;
316319
let mut running = lock.lock()?;
@@ -334,13 +337,13 @@ impl PyroscopeAgent {
334337
/// ```
335338
pub fn start(&mut self) {
336339
match self._start() {
337-
Ok(_) => log::trace!("PyroscopeAgent - Agent started"),
338-
Err(_) => log::error!("PyroscopeAgent - Error starting agent"),
340+
Ok(_) => log::trace!(target: LOG_TAG, "Agent started"),
341+
Err(_) => log::error!(target: LOG_TAG, "Error starting agent"),
339342
}
340343
}
341344

342345
fn _stop(&mut self) -> Result<()> {
343-
log::debug!("PyroscopeAgent - Stopping");
346+
log::debug!(target: LOG_TAG, "Stopping");
344347
// get tx and send termination signal
345348
if let Some(sender) = self.tx.take() {
346349
sender.send(0)?;
@@ -371,8 +374,8 @@ impl PyroscopeAgent {
371374
/// ```
372375
pub fn stop(&mut self) {
373376
match self._stop() {
374-
Ok(_) => log::trace!("PyroscopeAgent - Agent stopped"),
375-
Err(_) => log::error!("PyroscopeAgent - Error stopping agent"),
377+
Ok(_) => log::trace!(target: LOG_TAG, "Agent stopped"),
378+
Err(_) => log::error!(target: LOG_TAG, "Error stopping agent"),
376379
}
377380
}
378381

@@ -387,7 +390,7 @@ impl PyroscopeAgent {
387390
/// agent.stop()?;
388391
/// ```
389392
pub fn add_tags(&mut self, tags: &[(&str, &str)]) -> Result<()> {
390-
log::debug!("PyroscopeAgent - Adding tags");
393+
log::debug!(target: LOG_TAG, "Adding tags");
391394
// Check that tags are not empty
392395
if tags.is_empty() {
393396
return Ok(());
@@ -430,7 +433,7 @@ impl PyroscopeAgent {
430433
/// # }
431434
/// ```
432435
pub fn remove_tags(&mut self, tags: &[&str]) -> Result<()> {
433-
log::debug!("PyroscopeAgent - Removing tags");
436+
log::debug!(target: LOG_TAG, "Removing tags");
434437

435438
// Check that tags are not empty
436439
if tags.is_empty() {

0 commit comments

Comments
 (0)