mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Update dependencies and enhance logging functionality
- Added the `dirs` crate version 6.0.0 to manage directory paths more effectively. - Introduced a new `write_log_header` function to standardize log file headers, including project and command details. - Updated logging path to use the home directory for log storage, improving accessibility. - Adjusted documentation to reflect the new logging path format. These changes aim to improve the logging system's clarity and maintainability while ensuring proper directory management.
This commit is contained in:
parent
84253019c2
commit
77e214e02f
4 changed files with 29 additions and 4 deletions
|
|
@ -32,6 +32,27 @@ fn session_log_filename(command_name: &str) -> String {
|
|||
)
|
||||
}
|
||||
|
||||
fn write_log_header(file: &mut std::fs::File, command_name: &str, project_dir: Option<&Path>) {
|
||||
let now = time::OffsetDateTime::now_utc();
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
let project = project_dir
|
||||
.map(|p| p.display().to_string())
|
||||
.unwrap_or_else(|| "none".into());
|
||||
let cwd = std::env::current_dir()
|
||||
.map(|p| p.display().to_string())
|
||||
.unwrap_or_else(|_| "unknown".into());
|
||||
|
||||
let _ = writeln!(
|
||||
file,
|
||||
"=== Atlas v{version} ===\n\
|
||||
Command: {command_name}\n\
|
||||
Project: {project}\n\
|
||||
Working dir: {cwd}\n\
|
||||
Started: {now}\n\
|
||||
==="
|
||||
);
|
||||
}
|
||||
|
||||
pub fn init_logging(
|
||||
verbosity: u8,
|
||||
color: ColorChoice,
|
||||
|
|
@ -66,8 +87,8 @@ pub fn init_logging(
|
|||
|
||||
let mut file_guard: Option<tracing_appender::non_blocking::WorkerGuard> = None;
|
||||
|
||||
let file_layer = if let (Some(dir), Some(level)) = (project_dir, file_log_level) {
|
||||
let log_dir = dir.join(".atlas").join("logs");
|
||||
let file_layer = if let (Some(level), Some(home)) = (file_log_level, dirs::home_dir()) {
|
||||
let log_dir = home.join(".atlas").join("logs");
|
||||
|
||||
match std::fs::create_dir_all(&log_dir) {
|
||||
Ok(()) => {
|
||||
|
|
@ -81,7 +102,9 @@ pub fn init_logging(
|
|||
.append(true)
|
||||
.open(&log_path)
|
||||
{
|
||||
Ok(file) => {
|
||||
Ok(mut file) => {
|
||||
write_log_header(&mut file, command_name, project_dir);
|
||||
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file);
|
||||
file_guard = Some(guard);
|
||||
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ pub struct Project {
|
|||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ignore_hidden_services: Option<bool>,
|
||||
|
||||
/// Controls the log level for file-based logging to `.atlas/logs/`.
|
||||
/// Controls the log level for file-based logging to `~/.atlas/logs/`.
|
||||
/// Values: "trace" (default), "debug", "info", "warn", "error", "none".
|
||||
/// When "none", file logging is disabled entirely.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue