write log files to disk daily and on panic
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
22
Cargo.lock
generated
22
Cargo.lock
generated
@@ -917,6 +917,15 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-channel"
|
||||||
|
version = "0.5.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-deque"
|
name = "crossbeam-deque"
|
||||||
version = "0.8.5"
|
version = "0.8.5"
|
||||||
@@ -2568,6 +2577,7 @@ dependencies = [
|
|||||||
"tempfile",
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tracing-appender",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"tracing-wasm",
|
"tracing-wasm",
|
||||||
"uuid",
|
"uuid",
|
||||||
@@ -4427,6 +4437,18 @@ dependencies = [
|
|||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-appender"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-channel",
|
||||||
|
"thiserror",
|
||||||
|
"time",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-attributes"
|
name = "tracing-attributes"
|
||||||
version = "0.1.27"
|
version = "0.1.27"
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ bitflags = "2.5.0"
|
|||||||
uuid = { version = "1.10.0", features = ["v4"] }
|
uuid = { version = "1.10.0", features = ["v4"] }
|
||||||
indexmap = "2.6.0"
|
indexmap = "2.6.0"
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
|
tracing-appender = "0.2.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3.13.0"
|
tempfile = "3.13.0"
|
||||||
|
|||||||
@@ -11,8 +11,57 @@ use notedeck::Damus;
|
|||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
#[allow(unused_variables)] // need guard to live for lifetime of program
|
||||||
|
let (maybe_non_blocking, maybe_guard) =
|
||||||
|
if let Ok(log_path) = notedeck::DataPaths::Log.get_path() {
|
||||||
|
// Setup logging to file
|
||||||
|
use std::panic;
|
||||||
|
|
||||||
|
use tracing::error;
|
||||||
|
use tracing_appender::{
|
||||||
|
non_blocking,
|
||||||
|
rolling::{RollingFileAppender, Rotation},
|
||||||
|
};
|
||||||
|
|
||||||
|
let file_appender = RollingFileAppender::new(
|
||||||
|
Rotation::DAILY,
|
||||||
|
log_path,
|
||||||
|
format!("notedeck-{}.log", env!("CARGO_PKG_VERSION")),
|
||||||
|
);
|
||||||
|
panic::set_hook(Box::new(|panic_info| {
|
||||||
|
error!("Notedeck panicked: {:?}", panic_info);
|
||||||
|
}));
|
||||||
|
|
||||||
|
let (non_blocking, _guard) = non_blocking(file_appender);
|
||||||
|
|
||||||
|
(Some(non_blocking), Some(_guard))
|
||||||
|
} else {
|
||||||
|
(None, None)
|
||||||
|
};
|
||||||
|
|
||||||
// Log to stdout (if you run with `RUST_LOG=debug`).
|
// Log to stdout (if you run with `RUST_LOG=debug`).
|
||||||
tracing_subscriber::fmt::init();
|
if let Some(non_blocking_writer) = maybe_non_blocking {
|
||||||
|
use tracing::Level;
|
||||||
|
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
|
let console_layer = fmt::layer().with_target(true).with_writer(std::io::stdout);
|
||||||
|
|
||||||
|
// Create the file layer (writes to the file)
|
||||||
|
let file_layer = fmt::layer()
|
||||||
|
.with_ansi(false)
|
||||||
|
.with_writer(non_blocking_writer);
|
||||||
|
|
||||||
|
// Set up the subscriber to combine both layers
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(console_layer)
|
||||||
|
.with(file_layer)
|
||||||
|
.with(tracing_subscriber::filter::LevelFilter::from_level(
|
||||||
|
Level::INFO,
|
||||||
|
)) // Set log level
|
||||||
|
.init();
|
||||||
|
} else {
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
}
|
||||||
|
|
||||||
let _res = eframe::run_native(
|
let _res = eframe::run_native(
|
||||||
"Damus NoteDeck",
|
"Damus NoteDeck",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ mod abbrev;
|
|||||||
pub mod account_manager;
|
pub mod account_manager;
|
||||||
mod actionbar;
|
mod actionbar;
|
||||||
pub mod app_creation;
|
pub mod app_creation;
|
||||||
|
mod app_size_handler;
|
||||||
mod app_style;
|
mod app_style;
|
||||||
mod args;
|
mod args;
|
||||||
mod colors;
|
mod colors;
|
||||||
|
|||||||
Reference in New Issue
Block a user