Revert "b/logs: do some things to try to log panics on startups" (#148)

This commit is contained in:
Tyler Wilding 2023-04-01 00:55:42 -05:00 committed by GitHub
parent 56c7c7ff8d
commit 45c86dbfe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 84 deletions

1
src-tauri/Cargo.lock generated
View file

@ -2258,7 +2258,6 @@ dependencies = [
name = "opengoal-launcher"
version = "2.0.5"
dependencies = [
"backtrace",
"chrono",
"dir-diff",
"fern",

View file

@ -35,7 +35,6 @@ thiserror = "1.0.40"
rev_buf_reader = "0.3.0"
flate2 = "1.0.25"
tar = "0.4.38"
backtrace = "0.3.67"
[features]
# by default Tauri runs in production mode

View file

@ -7,36 +7,15 @@ use fern::colors::{Color, ColoredLevelConfig};
use tauri::{Manager, RunEvent};
use util::file::create_dir;
use backtrace::Backtrace;
use std::{env, io::Write};
use std::env;
mod commands;
mod config;
mod textures;
mod util;
fn panic_hook(info: &std::panic::PanicInfo) {
let backtrace = Backtrace::new();
log::error!("panic occurred: {:?}\n{:?}", info, backtrace);
match std::fs::File::create("og-launcher-crash.log") {
Ok(mut file) => {
if let Err(err) =
file.write_all(format!("panic occurred: {:?}\n{:?}", info, backtrace).as_bytes())
{
log::error!("unable to log crash report to a file - {:?}", err)
}
}
Err(err) => log::error!("unable to log crash report to a file - {:?}", err),
}
std::process::exit(1);
}
fn main() {
// In the event that some catastrophic happens, atleast log it out
// the panic_hook will log to a file in the folder of the executable
std::panic::set_hook(Box::new(panic_hook));
let tauri_setup = tauri::Builder::default()
tauri::Builder::default()
.setup(|app| {
// Setup Logging
let log_path = app
@ -58,7 +37,7 @@ fn main() {
// since almost all of them are the same as the color for the whole line, we
// just clone `colors_line` and overwrite our changes
let colors_level = colors_line.clone().info(Color::Cyan);
let log_setup_ok = fern::Dispatch::new()
fern::Dispatch::new()
// Perform allocation-free log formatting
.format(move |out, message, record| {
out.finish(format_args!(
@ -81,26 +60,23 @@ fn main() {
.chain(std::io::stdout())
.chain(fern::DateBased::new(&log_path, "/%Y-%m-%d.log"))
// Apply globally
.apply();
match log_setup_ok {
Ok(_) => {
log::info!("Logging Initialized");
// Truncate rotated log files to '5'
let mut paths: Vec<_> = std::fs::read_dir(&log_path)?.map(|r| r.unwrap()).collect();
paths.sort_by_key(|dir| dir.path());
paths.reverse();
let mut i = 0;
for path in paths {
i += 1;
log::info!("{}", path.path().display());
if i > 5 {
log::info!("deleting - {}", path.path().display());
std::fs::remove_file(path.path())?;
}
}
.apply()
.expect("Could not setup logs");
log::info!("Logging Initialized");
// Truncate rotated log files to '5'
let mut paths: Vec<_> = std::fs::read_dir(&log_path)?.map(|r| r.unwrap()).collect();
paths.sort_by_key(|dir| dir.path());
paths.reverse();
let mut i = 0;
for path in paths {
i += 1;
log::info!("{}", path.path().display());
if i > 5 {
log::info!("deleting - {}", path.path().display());
std::fs::remove_file(path.path())?;
}
Err(err) => log::error!("Could not initialize logging {:?}", err),
};
}
// Load the config (or initialize it with defaults)
//
@ -148,43 +124,11 @@ fn main() {
commands::window::open_dir_in_os
])
.build(tauri::generate_context!())
.map_err(|err| {
let backtrace = Backtrace::new();
log::error!(
"unexpected top level error occurred: {:?}\n{:?}",
err,
backtrace
);
match std::fs::File::create("og-launcher-crash.log") {
Ok(mut file) => {
if let Err(file_err) = file.write_all(
format!(
"unexpected top level error occurred: {:?}\n{:?}",
err, backtrace
)
.as_bytes(),
) {
log::error!("unable to log crash report to a file - {:?}", file_err)
}
}
Err(err) => log::error!("unable to log crash report to a file - {:?}", err),
.expect("error building tauri app")
.run(|_app_handle, event| match event {
RunEvent::ExitRequested { .. } => {
std::process::exit(0);
}
std::process::exit(1);
});
match tauri_setup {
Ok(app) => {
log::info!("application starting up");
app.run(|_app_handle, event| match event {
RunEvent::ExitRequested { .. } => {
log::info!("Exit requested, exiting!");
std::process::exit(0);
}
_ => (),
})
}
Err(err) => {
log::error!("Could not setup tauri application {:?}, exiting", err);
std::process::exit(1);
}
};
_ => (),
})
}

View file

@ -38,7 +38,10 @@
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
"timestampUrl": "",
"webviewInstallMode": {
"type": "embedBootstrapper"
}
}
},
"allowlist": {