feat: add hard limit to the game log file size
This commit is contained in:
parent
a72d1fb05c
commit
0c34ca2b31
6 changed files with 198 additions and 114 deletions
|
@ -311,36 +311,50 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
// Create new game.log file to log all the game output
|
// Create new game.log file to log all the game output
|
||||||
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
||||||
|
|
||||||
|
// Limit max amount of log data in a file
|
||||||
|
// This is needed to stop wine from flushing
|
||||||
|
// tons of debug info there
|
||||||
|
const LOG_FILE_LIMIT: usize = 8 * 1024 * 1024; // 8 MiB
|
||||||
|
|
||||||
|
let mut written = 0;
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Check if we've written less than a limit amount of data
|
||||||
if let Some(stdout) = &mut child.stdout {
|
if written < LOG_FILE_LIMIT {
|
||||||
let mut buf = Vec::new();
|
// Redirect stdout to the game.log file
|
||||||
|
if let Some(stdout) = &mut child.stdout {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,36 +264,50 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
// Create new game.log file to log all the game output
|
// Create new game.log file to log all the game output
|
||||||
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
||||||
|
|
||||||
|
// Limit max amount of log data in a file
|
||||||
|
// This is needed to stop wine from flushing
|
||||||
|
// tons of debug info there
|
||||||
|
const LOG_FILE_LIMIT: usize = 8 * 1024 * 1024; // 8 MiB
|
||||||
|
|
||||||
|
let mut written = 0;
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Check if we've written less than a limit amount of data
|
||||||
if let Some(stdout) = &mut child.stdout {
|
if written < LOG_FILE_LIMIT {
|
||||||
let mut buf = Vec::new();
|
// Redirect stdout to the game.log file
|
||||||
|
if let Some(stdout) = &mut child.stdout {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,36 +254,50 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
// Create new game.log file to log all the game output
|
// Create new game.log file to log all the game output
|
||||||
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
||||||
|
|
||||||
|
// Limit max amount of log data in a file
|
||||||
|
// This is needed to stop wine from flushing
|
||||||
|
// tons of debug info there
|
||||||
|
const LOG_FILE_LIMIT: usize = 8 * 1024 * 1024; // 8 MiB
|
||||||
|
|
||||||
|
let mut written = 0;
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Check if we've written less than a limit amount of data
|
||||||
if let Some(stdout) = &mut child.stdout {
|
if written < LOG_FILE_LIMIT {
|
||||||
let mut buf = Vec::new();
|
// Redirect stdout to the game.log file
|
||||||
|
if let Some(stdout) = &mut child.stdout {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,36 +265,50 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
// Create new game.log file to log all the game output
|
// Create new game.log file to log all the game output
|
||||||
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
||||||
|
|
||||||
|
// Limit max amount of log data in a file
|
||||||
|
// This is needed to stop wine from flushing
|
||||||
|
// tons of debug info there
|
||||||
|
const LOG_FILE_LIMIT: usize = 8 * 1024 * 1024; // 8 MiB
|
||||||
|
|
||||||
|
let mut written = 0;
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Check if we've written less than a limit amount of data
|
||||||
if let Some(stdout) = &mut child.stdout {
|
if written < LOG_FILE_LIMIT {
|
||||||
let mut buf = Vec::new();
|
// Redirect stdout to the game.log file
|
||||||
|
if let Some(stdout) = &mut child.stdout {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,36 +245,50 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
// Create new game.log file to log all the game output
|
// Create new game.log file to log all the game output
|
||||||
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
||||||
|
|
||||||
|
// Limit max amount of log data in a file
|
||||||
|
// This is needed to stop wine from flushing
|
||||||
|
// tons of debug info there
|
||||||
|
const LOG_FILE_LIMIT: usize = 8 * 1024 * 1024; // 8 MiB
|
||||||
|
|
||||||
|
let mut written = 0;
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Check if we've written less than a limit amount of data
|
||||||
if let Some(stdout) = &mut child.stdout {
|
if written < LOG_FILE_LIMIT {
|
||||||
let mut buf = Vec::new();
|
// Redirect stdout to the game.log file
|
||||||
|
if let Some(stdout) = &mut child.stdout {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,36 +263,50 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
// Create new game.log file to log all the game output
|
// Create new game.log file to log all the game output
|
||||||
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
let mut game_output = std::fs::File::create(consts::launcher_dir()?.join("game.log"))?;
|
||||||
|
|
||||||
|
// Limit max amount of log data in a file
|
||||||
|
// This is needed to stop wine from flushing
|
||||||
|
// tons of debug info there
|
||||||
|
const LOG_FILE_LIMIT: usize = 8 * 1024 * 1024; // 8 MiB
|
||||||
|
|
||||||
|
let mut written = 0;
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Check if we've written less than a limit amount of data
|
||||||
if let Some(stdout) = &mut child.stdout {
|
if written < LOG_FILE_LIMIT {
|
||||||
let mut buf = Vec::new();
|
// Redirect stdout to the game.log file
|
||||||
|
if let Some(stdout) = &mut child.stdout {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stdout.read_to_end(&mut buf)?;
|
stdout.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b" [stdout] ")?;
|
game_output.write_all(b" [stdout] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
stderr.read_to_end(&mut buf)?;
|
stderr.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
for line in buf.split(|c| c == &b'\n') {
|
for line in buf.split(|c| c == &b'\n') {
|
||||||
game_output.write_all(b"[!] [stderr] ")?;
|
game_output.write_all(b"[!] [stderr] ")?;
|
||||||
game_output.write_all(line)?;
|
game_output.write_all(line)?;
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
|
written += line.len() + 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue