replace logging with file logging

This commit is contained in:
acereca 2023-04-13 16:34:08 +02:00
parent edee082587
commit 62c9c3095b
3 changed files with 149 additions and 20 deletions

119
Cargo.lock generated
View File

@ -67,6 +67,25 @@ dependencies = [
"libc",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
dependencies = [
"cfg-if",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
@ -351,7 +370,7 @@ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"redox_syscall 0.2.16",
"smallvec",
"windows-sys",
]
@ -480,6 +499,12 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_syscall"
version = "0.2.16"
@ -495,6 +520,15 @@ version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -572,6 +606,17 @@ dependencies = [
"libc",
]
[[package]]
name = "simple-logging"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b00d48e85675326bb182a2286ea7c1a0b264333ae10f27a937a72be08628b542"
dependencies = [
"lazy_static",
"log",
"thread-id",
]
[[package]]
name = "slab"
version = "0.4.8"
@ -603,13 +648,17 @@ version = "0.2.0"
dependencies = [
"dashmap",
"glob",
"log",
"pest",
"pest_derive",
"serde",
"serde_json",
"simple-logging",
"tokio",
"tower-lsp",
"tracing-appender",
"tracing-subscriber",
"walkdir",
]
[[package]]
@ -643,6 +692,17 @@ dependencies = [
"syn",
]
[[package]]
name = "thread-id"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1"
dependencies = [
"libc",
"redox_syscall 0.1.57",
"winapi",
]
[[package]]
name = "thread_local"
version = "1.1.7"
@ -653,6 +713,33 @@ dependencies = [
"once_cell",
]
[[package]]
name = "time"
version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890"
dependencies = [
"itoa",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]]
name = "time-macros"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36"
dependencies = [
"time-core",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
@ -785,6 +872,17 @@ dependencies = [
"tracing-core",
]
[[package]]
name = "tracing-appender"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d48f71a791638519505cefafe162606f706c25592e4bde4d97600c0195312e"
dependencies = [
"crossbeam-channel",
"time",
"tracing-subscriber",
]
[[package]]
name = "tracing-attributes"
version = "0.1.23"
@ -888,6 +986,16 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@ -910,6 +1018,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View File

@ -12,4 +12,8 @@ tower-lsp = "*"
serde = "*"
serde_json = "*"
tracing-subscriber = "*"
tracing-appender = "*"
dashmap = "5.4.0"
log = "*"
simple-logging = "2.0.2"
walkdir = "*"

View File

@ -11,6 +11,9 @@ use tower_lsp::lsp_types::notification::Notification;
use tower_lsp::lsp_types::*;
use tower_lsp::{Client, LanguageServer, LspService, Server};
use log::{debug, info};
use walkdir::WalkDir;
extern crate glob;
extern crate pest;
#[macro_use]
@ -51,29 +54,31 @@ impl LanguageServer for Backend {
let root = init_params
.root_uri
.ok_or(Error::new(ErrorCode::InvalidParams))?;
self.client
.log_message(
MessageType::INFO,
format!("server initializing! ({:?})", root.path()),
)
.await;
info!(target: "Backend", "Initializing Language Server");
let pattern = root.path().to_string() + "/**/*.il";
self.client
.log_message(MessageType::INFO, format!("pattern used: {:?}", pattern))
.await;
let root_dir = root.path().to_string();
for entry in glob::glob(pattern.as_str()).expect("no file to cache in root_dir") {
match entry {
Ok(path) => {
self.cache.update(path.to_str().unwrap());
self.client
.log_message(MessageType::INFO, format!("caching {:?}", path.display()))
.await
info!(target: "Backend", "Caching started in '{}'", root_dir);
for entry in WalkDir::new(root_dir)
.follow_links(true)
.into_iter()
.filter_map(|e| e.ok())
{
let f_path = entry.path().to_str();
match f_path {
Some(path) => {
if path.ends_with(".il") {
info!("found '{}'", path);
self.cache.update(path);
}
}
Err(_) => {}
None => {}
}
}
info!(target: "Backend", "Caching finished. Found {} files.", self.cache.symbols.len());
debug!(target: "Backend", "{:?}", self.cache.symbols);
Ok(InitializeResult {
server_info: None,
@ -142,7 +147,9 @@ impl LanguageServer for Backend {
#[tokio::main]
async fn main() {
tracing_subscriber::fmt().init();
let writer = tracing_appender::rolling::never(".", "srls.out");
tracing_subscriber::fmt().with_writer(writer).init();
info!(target: "main", "Starting");
let (stdin, stdout) = (tokio::io::stdin(), tokio::io::stdout());
@ -150,5 +157,6 @@ async fn main() {
client,
cache: SymbolCache::new(),
});
info!("Creating server instance.");
Server::new(stdin, stdout, socket).serve(service).await;
}