Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Filter agent app-insights logs based on log::max_level #125

Merged
merged 4 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/agent/onefuzz-agent/src/tasks/fuzz/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::tasks::{
utils::{self, CheckNotify},
};
use anyhow::{Error, Result};
use appinsights::telemetry::SeverityLevel;
use onefuzz::{
expand::Expand,
fs::{has_files, set_executable, OwnedDir},
Expand Down
35 changes: 18 additions & 17 deletions src/agent/onefuzz/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,25 +341,26 @@ macro_rules! event {
#[macro_export]
macro_rules! log {
($level: expr, $msg: expr) => {{
use appinsights::telemetry::SeverityLevel;
use SeverityLevel::*;

{
let log_level = match $level {
SeverityLevel::Verbose => log::Level::Debug,
SeverityLevel::Information => log::Level::Info,
SeverityLevel::Warning => log::Level::Warn,
SeverityLevel::Error => log::Level::Error,
SeverityLevel::Critical => log::Level::Error,
};

let log_msg = $msg.to_string();
use appinsights::telemetry::SeverityLevel::{
Critical, Error, Information, Verbose, Warning,
};

log::log!(log_level, "{}", log_msg)
}
let log_level = match $level {
Verbose => log::Level::Debug,
Information => log::Level::Info,
Warning => log::Level::Warn,
Error => log::Level::Error,
Critical => log::Level::Error,
};

if let Some(client) = $crate::telemetry::client($crate::telemetry::ClientType::Instance) {
client.track_trace($msg, $level);
// while log::log will filter based on log level, the telemetry
// client does *not*.
if log_level <= log::max_level() {
bmc-msft marked this conversation as resolved.
Show resolved Hide resolved
log::log!(log_level, "{}", $msg.to_string());
if let Some(client) = $crate::telemetry::client($crate::telemetry::ClientType::Instance)
{
client.track_trace($msg, $level);
}
}
}};
}
Expand Down
1 change: 1 addition & 0 deletions src/runtime-tools/win64/onefuzz.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $env:Path += ";C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\;C:\onefuzz\
$env:ONEFUZZ_ROOT = "C:\onefuzz"
$env:ONEFUZZ_TOOLS = "C:\onefuzz\tools"
$env:ASAN_SYMBOLIZER_PATH = "llvm-symbolizer"
$env:RUST_LOG = "info"

$logFile = "C:\onefuzz.log"
function log ($message) {
Expand Down