diag: keep the previous run's log as diag.prev.log
This commit is contained in:
parent
769491ca66
commit
d69dcc8d67
1 changed files with 6 additions and 2 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
//! overlays and `shell_raise` calls with their results, native focus calls, and the shell document's
|
//! overlays and `shell_raise` calls with their results, native focus calls, and the shell document's
|
||||||
//! focus, blur and visibility changes. A line is an event name and a few words: never a URL, a
|
//! focus, blur and visibility changes. A line is an event name and a few words: never a URL, a
|
||||||
//! query, page text or anything about an account ([`clean`] keeps plain printable ASCII only and
|
//! query, page text or anything about an account ([`clean`] keeps plain printable ASCII only and
|
||||||
//! caps the length). The file is truncated at each launch with diagnostics on.
|
//! caps the length). Each launch with diagnostics on starts a new file; the one before it is kept as `diag.prev.log`.
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
@ -15,6 +15,7 @@ use std::time::Instant;
|
||||||
pub const ARG: &str = "--diag";
|
pub const ARG: &str = "--diag";
|
||||||
pub const ENV: &str = "WAYBETTER_DIAG";
|
pub const ENV: &str = "WAYBETTER_DIAG";
|
||||||
pub const FILE: &str = "diag.log";
|
pub const FILE: &str = "diag.log";
|
||||||
|
pub const PREVIOUS: &str = "diag.prev.log";
|
||||||
const MAX_LINE: usize = 300;
|
const MAX_LINE: usize = 300;
|
||||||
|
|
||||||
static ON: AtomicBool = AtomicBool::new(false);
|
static ON: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
@ -34,10 +35,13 @@ pub fn clean(line: &str) -> String {
|
||||||
line.chars().take(MAX_LINE).map(|ch| if (' '..='~').contains(&ch) { ch } else { '?' }).collect()
|
line.chars().take(MAX_LINE).map(|ch| if (' '..='~').contains(&ch) { ch } else { '?' }).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Starts writing to `dir/diag.log` (created, truncated). Nothing happens without a folder.
|
/// Starts writing to `dir/diag.log` (created, truncated); the previous run's log is kept as `diag.prev.log`.
|
||||||
|
/// Nothing happens without a folder.
|
||||||
pub fn start(dir: Option<PathBuf>) {
|
pub fn start(dir: Option<PathBuf>) {
|
||||||
let Some(dir) = dir else { return };
|
let Some(dir) = dir else { return };
|
||||||
let _ = std::fs::create_dir_all(&dir);
|
let _ = std::fs::create_dir_all(&dir);
|
||||||
|
// A run that went wrong is usually relaunched at once: keep its log.
|
||||||
|
let _ = std::fs::rename(dir.join(FILE), dir.join(PREVIOUS));
|
||||||
if let Ok(file) = std::fs::File::create(dir.join(FILE)) {
|
if let Ok(file) = std::fs::File::create(dir.join(FILE)) {
|
||||||
if let Ok(mut sink) = SINK.lock() {
|
if let Ok(mut sink) = SINK.lock() {
|
||||||
*sink = Some((file, Instant::now()));
|
*sink = Some((file, Instant::now()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue