mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-09-12 00:07:42 +03:00
Configure logging (-vv for debug level logs)
This commit is contained in:
parent
eff6fac9ec
commit
af1924404a
68
Cargo.lock
generated
68
Cargo.lock
generated
@ -208,6 +208,19 @@ version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"time",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.0.0-beta.2"
|
||||
@ -320,6 +333,15 @@ dependencies = [
|
||||
"instant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fern"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c9a4820f0ccc8a7afd67c39a0f1a0f4b07ca1725164271a64939d7aeb9af065"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futf"
|
||||
version = "0.1.4"
|
||||
@ -408,7 +430,7 @@ checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasi 0.9.0+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -449,6 +471,7 @@ dependencies = [
|
||||
"helix-core",
|
||||
"helix-view",
|
||||
"jsonrpc-core",
|
||||
"log",
|
||||
"lsp-types",
|
||||
"pathdiff",
|
||||
"serde",
|
||||
@ -472,12 +495,15 @@ name = "helix-term"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"clap",
|
||||
"crossterm",
|
||||
"fern",
|
||||
"futures-util",
|
||||
"helix-core",
|
||||
"helix-lsp",
|
||||
"helix-view",
|
||||
"log",
|
||||
"num_cpus",
|
||||
"smol",
|
||||
"tui",
|
||||
@ -672,6 +698,25 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.13.0"
|
||||
@ -997,9 +1042,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.45"
|
||||
version = "1.0.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea9c5432ff16d6152371f808fb5a871cd67368171b09bb21b43df8e4a47a3556"
|
||||
checksum = "5ad5de3220ea04da322618ded2c42233d02baca219d6f160a3e9c87cda16c942"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1054,6 +1099,17 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi 0.10.0+wasi-snapshot-preview1",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "0.3.4"
|
||||
@ -1160,6 +1216,12 @@ version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
|
||||
[[package]]
|
||||
name = "wepoll-sys"
|
||||
version = "3.0.1"
|
||||
|
@ -13,12 +13,13 @@ helix-view = { path = "../helix-view" }
|
||||
lsp-types = { version = "0.82", features = ["proposed"] }
|
||||
smol = "1.2"
|
||||
url = "2"
|
||||
pathdiff = "0.2.0"
|
||||
shellexpand = "2.0.0"
|
||||
pathdiff = "0.2"
|
||||
shellexpand = "2.0"
|
||||
glob = "0.3"
|
||||
anyhow = "1"
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
jsonrpc-core = "15.1"
|
||||
futures-util = "0.3"
|
||||
thiserror = "1.0.21"
|
||||
thiserror = "1"
|
||||
log = "0.4"
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,5 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use log::debug;
|
||||
|
||||
use crate::{Error, Message, Notification};
|
||||
|
||||
type Result<T> = core::result::Result<T, Error>;
|
||||
@ -114,7 +116,7 @@ pub async fn send_payload(&mut self, payload: Payload) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
pub async fn send(&mut self, request: String) -> anyhow::Result<()> {
|
||||
// println!("-> {}", request);
|
||||
debug!("-> {}", request);
|
||||
|
||||
// send the headers
|
||||
self.writer
|
||||
@ -135,11 +137,11 @@ pub async fn recv_msg(&mut self, msg: Message) -> anyhow::Result<()> {
|
||||
Message::Notification(jsonrpc::Notification { method, params, .. }) => {
|
||||
let notification = Notification::parse(&method, params);
|
||||
|
||||
// println!("<- {} {:?}", method, notification);
|
||||
debug!("<- {} {:?}", method, notification);
|
||||
self.incoming.send(notification).await?;
|
||||
}
|
||||
Message::Call(_call) => {
|
||||
// println!("<- {:?}", call);
|
||||
Message::Call(call) => {
|
||||
debug!("<- {:?}", call);
|
||||
// dispatch
|
||||
}
|
||||
};
|
||||
@ -149,7 +151,7 @@ pub async fn recv_msg(&mut self, msg: Message) -> anyhow::Result<()> {
|
||||
pub async fn recv_response(&mut self, output: jsonrpc::Output) -> anyhow::Result<()> {
|
||||
match output {
|
||||
jsonrpc::Output::Success(jsonrpc::Success { id, result, .. }) => {
|
||||
// println!("<- {}", result);
|
||||
debug!("<- {}", result);
|
||||
|
||||
let tx = self
|
||||
.pending_requests
|
||||
|
@ -19,10 +19,15 @@ helix-lsp = { path = "../helix-lsp"}
|
||||
anyhow = "1"
|
||||
|
||||
smol = "1"
|
||||
num_cpus = "1.13"
|
||||
num_cpus = "1"
|
||||
# tui = { version = "0.12", default-features = false, features = ["crossterm"] }
|
||||
tui = { git = "https://github.com/fdehau/tui-rs", default-features = false, features = ["crossterm"] }
|
||||
crossterm = { version = "0.18", features = ["event-stream"] }
|
||||
clap = { version = "3.0.0-beta.2 ", default-features = false, features = ["std", "cargo"] }
|
||||
|
||||
futures-util = "0.3"
|
||||
|
||||
# Logging
|
||||
fern = "0.6"
|
||||
chrono = "0.4"
|
||||
log = "0.4"
|
||||
|
@ -11,6 +11,39 @@
|
||||
|
||||
static EX: smol::Executor = smol::Executor::new();
|
||||
|
||||
fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
|
||||
let mut base_config = fern::Dispatch::new();
|
||||
|
||||
// Let's say we depend on something which whose "info" level messages are too
|
||||
// verbose to include in end-user output. If we don't need them,
|
||||
// let's not include them.
|
||||
// .level_for("overly-verbose-target", log::LevelFilter::Warn)
|
||||
|
||||
base_config = match verbosity {
|
||||
0 => base_config.level(log::LevelFilter::Warn),
|
||||
1 => base_config.level(log::LevelFilter::Info),
|
||||
2 => base_config.level(log::LevelFilter::Debug),
|
||||
_3_or_more => base_config.level(log::LevelFilter::Trace),
|
||||
};
|
||||
|
||||
// Separate file config so we can include year, month and day in file logs
|
||||
let file_config = fern::Dispatch::new()
|
||||
.format(|out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"{} {} [{}] {}",
|
||||
chrono::Local::now().format("%Y-%m-%dT%H:%M:%S%.3f"),
|
||||
record.target(),
|
||||
record.level(),
|
||||
message
|
||||
))
|
||||
})
|
||||
.chain(fern::log_file("helix.log")?);
|
||||
|
||||
base_config.chain(file_config).apply()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
let args = clap::app_from_crate!()
|
||||
.arg(
|
||||
@ -20,8 +53,19 @@ fn main() -> Result<(), Error> {
|
||||
.multiple(true)
|
||||
.index(1),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("verbose")
|
||||
.about("Increases logging verbosity each use for up to 3 times")
|
||||
.short('v')
|
||||
.takes_value(false)
|
||||
.multiple_occurrences(true),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let verbosity: u64 = args.occurrences_of("verbose");
|
||||
|
||||
setup_logging(verbosity).expect("failed to initialize logging.");
|
||||
|
||||
for _ in 0..num_cpus::get() {
|
||||
std::thread::spawn(move || smol::block_on(EX.run(smol::future::pending::<()>())));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user