diff --git a/guide/troubleshooting.md b/guide/troubleshooting.md index 7b97696..8b2e949 100644 --- a/guide/troubleshooting.md +++ b/guide/troubleshooting.md @@ -45,11 +45,14 @@ Logging options are controlled by environment variables: accepted are `google` (the default, like the Google [glog](https://github.com/google/glog) package) and `google-systemd` (a variation for better systemd compatibility). +* `MOONFIRE_COLOR` controls color coding when using the `google` format. + It accepts `on`, `off`, or `auto`. `auto` means to color code if stderr + is a terminal. * Errors include a backtrace if `RUST_BACKTRACE=1` is set. If you use Docker, set these via Docker's `--env` argument. -With the default `MOONFIRE_FORMAT=glog`, log lines are in the following +With the default `MOONFIRE_FORMAT=google`, log lines are in the following format: ```text diff --git a/server/Cargo.lock b/server/Cargo.lock index 9937cff..52bab35 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -1274,9 +1274,10 @@ dependencies = [ [[package]] name = "mylog" version = "0.1.0" -source = "git+https://github.com/scottlamb/mylog#64519c6d9d4587d803900b82a83b45b35939b8f7" +source = "git+https://github.com/scottlamb/mylog#1406a8d794d799971e0e1079d5188d2dc339c584" dependencies = [ "chrono", + "libc", "log", "parking_lot", ] diff --git a/server/src/main.rs b/server/src/main.rs index 602b60c..cc81553 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,5 +1,5 @@ // This file is part of Moonfire NVR, a security camera network video recorder. -// Copyright (C) 2020 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt. +// Copyright (C) 2021 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt. // SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception. #![cfg_attr(all(feature = "nightly", test), feature(test))] @@ -116,6 +116,12 @@ fn main() { .and_then(|s| mylog::Format::from_str(&s)) .unwrap_or(mylog::Format::Google), ) + .set_color( + ::std::env::var("MOONFIRE_COLOR") + .map_err(|_| ()) + .and_then(|s| mylog::ColorMode::from_str(&s)) + .unwrap_or(mylog::ColorMode::Auto), + ) .set_spec(&::std::env::var("MOONFIRE_LOG").unwrap_or("info".to_owned())) .build(); h.clone().install().unwrap();