--- /dev/null
+// Copyright 2020-2021 Ian Jackson and contributors to Otter
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+use otter::prelude::*;
+
+use ansi_term::Style;
+use flexi_logger::{style, TS_DASHES_BLANK_COLONS_DOT_BLANK};
+use flexi_logger::{AdaptiveFormat, DeferredNow, FormatFunction, Record};
+
+#[throws(io::Error)]
+fn generic_format(w: &mut dyn io::Write,
+ now: &mut DeferredNow, record: &Record,
+ style: Style) {
+ write!(w, "[{}] {} [{}] {}:{}: {}",
+ now.format(TS_DASHES_BLANK_COLONS_DOT_BLANK),
+ style.paint(record.level().to_string()),
+ record.module_path().unwrap_or("<unnamed>"),
+ record.file().unwrap_or("<unnamed>"),
+ record.line().unwrap_or(0),
+ &record.args())?;
+}
+
+#[throws(io::Error)]
+fn basic_format(w: &mut dyn std::io::Write,
+ now: &mut DeferredNow, record: &Record) {
+ generic_format(w, now, record, default())?;
+}
+
+#[throws(io::Error)]
+fn coloured_format(w: &mut dyn io::Write,
+ now: &mut DeferredNow, record: &Record) {
+ generic_format(w, now, record, style(record.level()))?;
+}
+
+pub const BASIC_FORMAT: FormatFunction = basic_format;
+pub const ADAPTIVE_FORMAT: AdaptiveFormat = AdaptiveFormat::Custom(
+ basic_format, coloured_format
+);
pub mod api;
pub mod cmdlistener;
+pub mod logging;
pub mod session;
pub mod sse;
let c = config();
- flexi_logger::Logger::with(log_config()).start()?;
+ flexi_logger::Logger::with(log_config())
+ .format(logging::BASIC_FORMAT)
+ .adaptive_format_for_stderr(logging::ADAPTIVE_FORMAT)
+ .adaptive_format_for_stdout(logging::ADAPTIVE_FORMAT)
+ .start()?;
debug!("resolved config: {:#?}", c);