mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
[BEEEP] Use tracing in desktop_proxy (#16758)
This commit is contained in:
78
apps/desktop/desktop_native/Cargo.lock
generated
78
apps/desktop/desktop_native/Cargo.lock
generated
@@ -891,15 +891,6 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "desktop_core"
|
||||
version = "0.0.0"
|
||||
@@ -995,10 +986,10 @@ dependencies = [
|
||||
"desktop_core",
|
||||
"embed_plist",
|
||||
"futures",
|
||||
"log",
|
||||
"simplelog",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2074,12 +2065,6 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.46"
|
||||
@@ -2121,15 +2106,6 @@ dependencies = [
|
||||
"libm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2"
|
||||
version = "0.6.1"
|
||||
@@ -2550,12 +2526,6 @@ dependencies = [
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
@@ -3069,17 +3039,6 @@ dependencies = [
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simplelog"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16257adbfaef1ee58b1363bdc0664c9b8e1e30aed86049635fb5f147d065a9c0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"termcolor",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.11"
|
||||
@@ -3321,39 +3280,6 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"libc",
|
||||
"num-conv",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinystr"
|
||||
version = "0.8.1"
|
||||
|
||||
@@ -9,10 +9,10 @@ publish = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
desktop_core = { path = "../core" }
|
||||
futures = { workspace = true }
|
||||
log = { workspace = true }
|
||||
simplelog = { workspace = true }
|
||||
tokio = { workspace = true, features = ["io-std", "io-util", "macros", "rt"] }
|
||||
tokio-util = { workspace = true, features = ["codec"] }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
embed_plist = { workspace = true }
|
||||
|
||||
@@ -2,8 +2,11 @@ use std::path::Path;
|
||||
|
||||
use desktop_core::ipc::{MESSAGE_CHANNEL_BUFFER, NATIVE_MESSAGING_BUFFER_SIZE};
|
||||
use futures::{FutureExt, SinkExt, StreamExt};
|
||||
use log::*;
|
||||
use tokio_util::codec::LengthDelimitedCodec;
|
||||
use tracing::{debug, error, info, level_filters::LevelFilter};
|
||||
use tracing_subscriber::{
|
||||
fmt, layer::SubscriberExt as _, util::SubscriberInitExt as _, EnvFilter, Layer as _,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod windows;
|
||||
@@ -11,30 +14,38 @@ mod windows;
|
||||
#[cfg(target_os = "macos")]
|
||||
embed_plist::embed_info_plist!("../../../resources/info.desktop_proxy.plist");
|
||||
|
||||
const ENV_VAR_PROXY_LOG_LEVEL: &str = "PROXY_LOG_LEVEL";
|
||||
|
||||
fn init_logging(log_path: &Path, console_level: LevelFilter, file_level: LevelFilter) {
|
||||
use simplelog::{ColorChoice, CombinedLogger, Config, SharedLogger, TermLogger, TerminalMode};
|
||||
let console_filter = EnvFilter::builder()
|
||||
.with_default_directive(console_level.into())
|
||||
.with_env_var(ENV_VAR_PROXY_LOG_LEVEL)
|
||||
.from_env_lossy();
|
||||
|
||||
let config = Config::default();
|
||||
|
||||
let mut loggers: Vec<Box<dyn SharedLogger>> = Vec::new();
|
||||
loggers.push(TermLogger::new(
|
||||
console_level,
|
||||
config.clone(),
|
||||
TerminalMode::Stderr,
|
||||
ColorChoice::Auto,
|
||||
));
|
||||
let console_layer = fmt::layer()
|
||||
.with_writer(std::io::stderr)
|
||||
.with_filter(console_filter);
|
||||
|
||||
match std::fs::File::create(log_path) {
|
||||
Ok(file) => {
|
||||
loggers.push(simplelog::WriteLogger::new(file_level, config, file));
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Can't create file: {e}");
|
||||
}
|
||||
}
|
||||
let file_filter = EnvFilter::builder()
|
||||
.with_default_directive(file_level.into())
|
||||
.from_env_lossy();
|
||||
|
||||
if let Err(e) = CombinedLogger::init(loggers) {
|
||||
eprintln!("Failed to initialize logger: {e}");
|
||||
let file_layer = fmt::layer()
|
||||
.with_writer(file)
|
||||
.with_ansi(false)
|
||||
.with_filter(file_filter);
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(console_layer)
|
||||
.with(file_layer)
|
||||
.init();
|
||||
}
|
||||
Err(error) => {
|
||||
tracing_subscriber::registry().with(console_layer).init();
|
||||
error!(%error, ?log_path, "Could not create log file.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,12 +76,7 @@ async fn main() {
|
||||
path
|
||||
};
|
||||
|
||||
let level = std::env::var("PROXY_LOG_LEVEL")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(LevelFilter::Info);
|
||||
|
||||
init_logging(&log_path, level, LevelFilter::Info);
|
||||
init_logging(&log_path, LevelFilter::INFO, LevelFilter::INFO);
|
||||
|
||||
info!("Starting Bitwarden IPC Proxy.");
|
||||
|
||||
@@ -88,7 +94,7 @@ async fn main() {
|
||||
// - Origin of the extension that started it (in the form `chrome-extension://[ID]`).
|
||||
|
||||
let args: Vec<_> = std::env::args().skip(1).collect();
|
||||
info!("Process args: {:?}", args);
|
||||
info!(?args, "Process args");
|
||||
|
||||
// Setup two channels, one for sending messages to the desktop application (`out`) and one for receiving messages from the desktop application (`in`)
|
||||
let (in_send, in_recv) = tokio::sync::mpsc::channel(MESSAGE_CHANNEL_BUFFER);
|
||||
@@ -123,12 +129,12 @@ async fn main() {
|
||||
info!("IPC client finished successfully.");
|
||||
std::process::exit(0);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
error!("IPC client connection error: {}", e);
|
||||
Ok(Err(error)) => {
|
||||
error!(error, "IPC client connection error.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
Err(e) => {
|
||||
error!("IPC client spawn error: {}", e);
|
||||
Err(error) => {
|
||||
error!(%error, "IPC client spawn error.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -138,7 +144,7 @@ async fn main() {
|
||||
msg = out_recv.recv() => {
|
||||
match msg {
|
||||
Some(msg) => {
|
||||
debug!("OUT: {}", msg);
|
||||
debug!(msg, "OUT");
|
||||
stdout.send(msg.into()).await.unwrap();
|
||||
}
|
||||
None => {
|
||||
@@ -155,12 +161,12 @@ async fn main() {
|
||||
|
||||
match msg {
|
||||
Some(Ok(msg)) => {
|
||||
let m = String::from_utf8(msg.to_vec()).unwrap();
|
||||
debug!("IN: {}", m);
|
||||
in_send.send(m).await.unwrap();
|
||||
let msg = String::from_utf8(msg.to_vec()).unwrap();
|
||||
debug!(msg, "IN");
|
||||
in_send.send(msg).await.unwrap();
|
||||
}
|
||||
Some(Err(e)) => {
|
||||
error!("Error parsing input: {}", e);
|
||||
Some(Err(error)) => {
|
||||
error!(%error, "Error parsing input.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
None => {
|
||||
|
||||
Reference in New Issue
Block a user