JSON-serializes `log_line` to the file. Prints to stdout/stderr when `!suppress_stdout`.
(&self, log_line: LogLine)
| 43 | |
| 44 | /// JSON-serializes `log_line` to the file. Prints to stdout/stderr when `!suppress_stdout`. |
| 45 | pub fn log(&self, log_line: LogLine) { |
| 46 | if let Ok(mut guard) = self.file.lock() |
| 47 | && let Some(f) = guard.as_mut() |
| 48 | && let Ok(json) = serde_json::to_string(&log_line) |
| 49 | { |
| 50 | let _ = writeln!(f, "{json}"); |
| 51 | } |
| 52 | |
| 53 | if !self.suppress_stdout { |
| 54 | match &log_line { |
| 55 | LogLine::Message { |
| 56 | level: Level::Warning | Level::Error, |
| 57 | message, |
| 58 | .. |
| 59 | } => eprintln!("{message}"), |
| 60 | LogLine::Message { message, .. } => println!("{message}"), |
| 61 | _ => {} |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | fn open_append(path: &Path) -> Option<File> { |
| 67 | if let Some(parent) = path.parent() { |
no outgoing calls