8000 feat(core): watcher options by ematipico · Pull Request #8071 · biomejs/biome · GitHub
[go: up one dir, main page]

Skip to content
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
48 changes: 48 additions & 0 deletions .changeset/curly-facts-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
"@biomejs/biome": patch
---

Revamped the logging options for all Biome commands. Now the commands `format`, `lint`, `check`, `ci`, `search`, `lsp-proxy` and `start` accept the following CLI options.

Some options might have been present before, but they were inconsistent. Plus, all new options have an environment variable as aliases.

#### `--log-file`

Optional path/file to redirect log messages to. This option is applicable only to the CLI. If omitted, logs are printed to stdout.

Environment variable alias: `BIOME_LOG_FILE`

#### `--log-prefix-name`

Allows changing the prefix applied to the file name of the logs. This option is applicable only to the daemon.

Environment variable alias: `BIOME_LOG_PREFIX_NAME`

#### `--log-path`

Allows changing the folder where logs are stored. This option is applicable only to the daemon.

Environment variable alias: `BIOME_LOG_PATH`

#### `--log-level`

The level of logging. In order, from the most verbose to the least verbose: `debug`, `info`, `warn`, `error`

The value `none` won't show any logging.

Environment variable alias: `BIOME_LOG_LEVEL`

#### `--log-kind`

What the log should look like.

Environment variable alias: `BIOME_LOG_KIND`

#### Reduce dumping of LSP logs

When you use a Biome editor extension, Biome's Daemon dumps its logs using the `debug` level. If you want to reduce
the quantity of these logs, you can now customize it:

```shell
BIOME_LOG_LEVEL=info biome lsp-proxy
```
24 changes: 24 additions & 0 deletions .changeset/every-beers-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
"@biomejs/biome": minor
---

Added new CLI options to the commands `lsp-proxy` and `start` that allow to control the Biome file watcher.

#### `--watcher-kind`

Controls how the Biome file watcher should behave. By default, Biome chooses the best watcher strategy for the
current OS, however sometimes this could result in some issues, such as folders locked.

The option accepts the current values:
- `recommended`: the default option, which chooses the best watcher for the current platform.
- `polling`: uses the polling strategy.
- `none`: it doesn't enable the watcher. When the watcher is disabled, changes to files aren't recorded anymore by Biome. This might have
repercussions on some lint rules that might rely on updated types or updated paths.

The environment variable `BIOME_WATCHER_KIND` can be used as alias.

#### `--watcher-polling-interval`

The polling interval in milliseconds. This is only applicable when using the `polling` watcher. It defaults to `2000` milliseconds.

The environment variable `BIOME_WATCHER_POLLING_INTERVAL` can be used as alias.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions crates/biome_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::LoggingLevel;
use crate::logging::LoggingKind;
use biome_configuration::ConfigurationPathHint;
use biome_diagnostics::Severity;
use bpaf::Bpaf;
Expand Down Expand Up @@ -61,33 +59,6 @@ pub struct CliOptions {
)]
pub reporter: CliReporter,

/// Optional path to redirect log messages to.
///
/// If omitted, logs are printed to stdout.
#[bpaf(long("log-file"))]
pub log_file: Option<String>,

/// The level of logging. In order, from the most verbose to the least
/// verbose: debug, info, warn, error.
///
/// The value `none` won't show any logging.
#[bpaf(
long("log-level"),
argument("none|debug|info|warn|error"),
fallback(LoggingLevel::default()),
display_fallback
)]
pub log_level: LoggingLevel,

/// How the log should look like.
#[bpaf(
long("log-kind"),
argument("pretty|compact|json"),
fallback(LoggingKind::default()),
display_fallback
)]
pub log_kind: LoggingKind,

/// The level of diagnostics to show. In order, from the lowest to the most important: info, warn, error. Passing `--diagnostic-level=error` will cause Biome to print only diagnostics that contain only errors.
#[bpaf(
long("diagnostic-level"),
Expand Down
58 changes: 31 additions & 27 deletions crates/biome_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::logging::LogOptions;
use crate::{
CliDiagnostic, CliSession, open_transport,
service::{self, ensure_daemon, open_socket, run_daemon},
};
use biome_console::{ConsoleExt, markup};
use biome_fs::OsFileSystem;
use biome_lsp::ServerFactory;
use biome_service::{TransportError, Watcher, WorkspaceError, workspace::WorkspaceClient};
use camino::{Utf8Path, Utf8PathBuf};
use biome_service::{
TransportError, Watcher, WatcherOptions, WorkspaceError, workspace::WorkspaceClient,
};
use camino::Utf8PathBuf;
use std::{env, fs, process};
use tokio::io;
use tokio::runtime::Runtime;
Expand All @@ -23,11 +26,11 @@ use tracing_tree::HierarchicalLayer;

pub(crate) fn start(
session: CliSession,
log_path: Option<Utf8PathBuf>,
log_file_name_prefix: Option<String>,
watcher_options: WatcherOptions,
log_options: LogOptions,
) -> Result<(), CliDiagnostic> {
let rt = Runtime::new()?;
let did_spawn = rt.block_on(ensure_daemon(false, log_path, log_file_name_prefix))?;
let did_spawn = rt.block_on(ensure_daemon(false, watcher_options, log_options))?;

if did_spawn {
session.app.console.log(markup! {
Expand Down Expand Up @@ -68,21 +71,26 @@ pub(crate) fn stop(session: CliSession) -> Result<(), CliDiagnostic> {

pub(crate) fn run_server(
stop_on_disconnect: bool,
log_path: Option<Utf8PathBuf>,
log_file_name_prefix: Option<String>,
watcher_options: WatcherOptions,
log_options: LogOptions,
) -> Result<(), CliDiagnostic> {
setup_tracing_subscriber(log_path.as_deref(), log_file_name_prefix.as_deref());
setup_tracing_subscriber(
log_options.log_path.clone(),
log_options.log_prefix_name.clone(),
);

let span = debug_span!(
"Running Server",
pid = std::process::id(),
log_path = &log_options.log_path.as_str(),
log_file_name_prefix = &log_options.log_prefix_name.as_str(),
);

let (watcher, instruction_channel) = Watcher::new()?;
let (watcher, instruction_channel) = Watcher::new(watcher_options)?;

let rt = Runtime::new()?;
let factory = ServerFactory::new(stop_on_disconnect, instruction_channel.sender.clone());
let cancellation = factory.cancellation();
let span = debug_span!("Running Server",
pid = std::process::id(),
log_path = ?log_path.as_ref(),
log_file_name_prefix = &log_file_name_prefix.as_deref(),
);

let workspace = factory.workspace();
rt.spawn_blocking(move || {
Expand Down Expand Up @@ -114,11 +122,11 @@ pub(crate) fn print_socket() -> Result<(), CliDiagnostic> {
}

pub(crate) fn lsp_proxy(
log_path: Option<Utf8PathBuf>,
log_file_name_prefix: Option<String>,
watcher_options: WatcherOptions,
log_options: LogOptions,
) -> Result<(), CliDiagnostic> {
let rt = Runtime::new()?;
rt.block_on(start_lsp_proxy(&rt, log_path, log_file_name_prefix))?;
rt.block_on(start_lsp_proxy(&rt, watcher_options, log_options))?;

Ok(())
}
Expand All @@ -128,10 +136,10 @@ pub(crate) fn lsp_proxy(
/// Copy to the process on `stdout` when the LSP responds to a message
async fn start_lsp_proxy(
rt: &Runtime,
log_path: Option<Utf8PathBuf>,
log_file_name_prefix: Option<String>,
watcher_options: WatcherOptions,
log_options: LogOptions,
) -> Result<(), CliDiagnostic> {
ensure_daemon(true, log_path, log_file_name_prefix).await?;
ensure_daemon(true, watcher_options, log_options).await?;

match open_socket().await? {
Some((mut owned_read_half, mut owned_write_half)) => {
Expand Down Expand Up @@ -206,17 +214,13 @@ pub(crate) fn read_most_recent_log_file(
/// is written to log files rotated on a hourly basis (in
/// `biome-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
/// directory)
fn setup_tracing_subscriber(log_path: Option<&Utf8Path>, log_file_name_prefix: Option<&str>) {
let biome_log_path = log_path.map_or_else(
|| biome_fs::ensure_cache_dir().join("biome-logs"),
|path| path.to_path_buf(),
);
fn setup_tracing_subscriber(log_path: Utf8PathBuf, log_file_name_prefix: String) {
let appender_builder = tracing_appender::rolling::RollingFileAppender::builder();
let file_appender = appender_builder
.filename_prefix(log_file_name_prefix.map_or(String::from("server.log"), Into::into))
.filename_prefix(log_file_name_prefix)
.max_log_files(7)
.rotation(Rotation::HOURLY)
.build(biome_log_path)
.build(log_path)
.expect("Failed to start the logger for the daemon.");

registry()
Expand Down
Loading
0