fix(core): fix logging when directory does not exist (#30944)
This commit is contained in:
parent
766d1b32e0
commit
7a62c7374b
@ -1,4 +1,6 @@
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
use std::env;
|
||||||
|
use std::fs::create_dir_all;
|
||||||
use std::io::IsTerminal;
|
use std::io::IsTerminal;
|
||||||
use tracing::{Event, Level, Subscriber};
|
use tracing::{Event, Level, Subscriber};
|
||||||
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
||||||
@ -101,8 +103,28 @@ pub(crate) fn enable_logger() {
|
|||||||
.unwrap_or_else(|_| EnvFilter::new("ERROR")),
|
.unwrap_or_else(|_| EnvFilter::new("ERROR")),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let registry = tracing_subscriber::registry().with(stdout_layer);
|
||||||
|
|
||||||
|
if env::var("NX_NATIVE_FILE_LOGGING").is_err() {
|
||||||
|
// File logging is not enabled
|
||||||
|
registry.try_init().ok();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let log_dir = ".nx/workspace-data";
|
||||||
|
|
||||||
|
if let Err(e) = create_dir_all(log_dir) {
|
||||||
|
// Could not create the directory, so we will not log to file
|
||||||
|
println!(
|
||||||
|
"Logging to a file was not enabled because Nx could not create the {} directory for logging. Error: {}",
|
||||||
|
log_dir, e
|
||||||
|
);
|
||||||
|
registry.try_init().ok();
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let file_appender: RollingFileAppender =
|
let file_appender: RollingFileAppender =
|
||||||
RollingFileAppender::new(Rotation::NEVER, ".nx/workspace-data", "nx.log");
|
RollingFileAppender::new(Rotation::NEVER, log_dir, "nx.log");
|
||||||
let file_layer = tracing_subscriber::fmt::layer()
|
let file_layer = tracing_subscriber::fmt::layer()
|
||||||
.with_writer(file_appender)
|
.with_writer(file_appender)
|
||||||
.event_format(NxLogFormatter)
|
.event_format(NxLogFormatter)
|
||||||
@ -111,9 +133,6 @@ pub(crate) fn enable_logger() {
|
|||||||
EnvFilter::try_from_env("NX_NATIVE_FILE_LOGGING")
|
EnvFilter::try_from_env("NX_NATIVE_FILE_LOGGING")
|
||||||
.unwrap_or_else(|_| EnvFilter::new("ERROR")),
|
.unwrap_or_else(|_| EnvFilter::new("ERROR")),
|
||||||
);
|
);
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(stdout_layer)
|
registry.with(file_layer).try_init().ok();
|
||||||
.with(file_layer)
|
|
||||||
.try_init()
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import type { NxJsonConfiguration } from '../config/nx-json';
|
import type { NxJsonConfiguration } from '../config/nx-json';
|
||||||
import { readNxJsonFromDisk } from '../devkit-internals';
|
import { readNxJsonFromDisk } from '../devkit-internals';
|
||||||
|
import { IS_WASM } from '../native';
|
||||||
import { isCI } from '../utils/is-ci';
|
import { isCI } from '../utils/is-ci';
|
||||||
|
|
||||||
let tuiEnabled = undefined;
|
let tuiEnabled = undefined;
|
||||||
@ -31,7 +32,7 @@ export function isTuiEnabled(
|
|||||||
|
|
||||||
// Windows is not working well right now, temporarily disable it on Windows even if it has been specified as enabled
|
// Windows is not working well right now, temporarily disable it on Windows even if it has been specified as enabled
|
||||||
// TODO(@JamesHenry): Remove this check once Windows issues are fixed.
|
// TODO(@JamesHenry): Remove this check once Windows issues are fixed.
|
||||||
if (isCI() || isWindows) {
|
if (isCI() || isWindows || IS_WASM) {
|
||||||
tuiEnabled = false;
|
tuiEnabled = false;
|
||||||
process.env.NX_TUI = 'false';
|
process.env.NX_TUI = 'false';
|
||||||
return tuiEnabled;
|
return tuiEnabled;
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import { runCommands } from '../executors/run-commands/run-commands.impl';
|
|||||||
import { getTaskDetails, hashTask } from '../hasher/hash-task';
|
import { getTaskDetails, hashTask } from '../hasher/hash-task';
|
||||||
import { TaskHasher } from '../hasher/task-hasher';
|
import { TaskHasher } from '../hasher/task-hasher';
|
||||||
import {
|
import {
|
||||||
|
IS_WASM,
|
||||||
parseTaskStatus,
|
parseTaskStatus,
|
||||||
RunningTasksService,
|
RunningTasksService,
|
||||||
TaskDetails,
|
TaskDetails,
|
||||||
@ -55,7 +56,9 @@ export class TaskOrchestrator {
|
|||||||
this.tuiEnabled
|
this.tuiEnabled
|
||||||
);
|
);
|
||||||
|
|
||||||
private runningTasksService = new RunningTasksService(getDbConnection());
|
private runningTasksService = !IS_WASM
|
||||||
|
? new RunningTasksService(getDbConnection())
|
||||||
|
: null;
|
||||||
private tasksSchedule = new TasksSchedule(
|
private tasksSchedule = new TasksSchedule(
|
||||||
this.projectGraph,
|
this.projectGraph,
|
||||||
this.taskGraph,
|
this.taskGraph,
|
||||||
@ -686,7 +689,10 @@ export class TaskOrchestrator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async startContinuousTask(task: Task, groupId: number) {
|
async startContinuousTask(task: Task, groupId: number) {
|
||||||
if (this.runningTasksService.getRunningTasks([task.id]).length) {
|
if (
|
||||||
|
this.runningTasksService &&
|
||||||
|
this.runningTasksService.getRunningTasks([task.id]).length
|
||||||
|
) {
|
||||||
await this.preRunSteps([task], { groupId });
|
await this.preRunSteps([task], { groupId });
|
||||||
|
|
||||||
if (this.tuiEnabled) {
|
if (this.tuiEnabled) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user