aboutsummaryrefslogtreecommitdiff
path: root/src/utils/mod.rs
diff options
context:
space:
mode:
authornotgne22020-12-27 10:48:18 -0700
committernotgne22020-12-27 10:52:37 -0700
commit4461d1ea3f494778f07041164f6b8a252bd26ea2 (patch)
tree85fc2196e5c6869947c5f2d92713ac2b3bde8e2b /src/utils/mod.rs
parent91e934fd9e1e06044f75a3e3ad998813c2a90fb5 (diff)
Replace logger, add more logging options including files
Diffstat (limited to '')
-rw-r--r--src/utils/mod.rs95
1 files changed, 92 insertions, 3 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 5770f98..42c81f7 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -3,14 +3,14 @@
//
// SPDX-License-Identifier: MPL-2.0
-use rnix::{types::*, NodeOrToken, SyntaxKind::*, SyntaxNode};
-
-use std::path::PathBuf;
+use rnix::{types::*, SyntaxKind::*};
use merge::Merge;
use thiserror::Error;
+use flexi_logger::*;
+
#[macro_export]
macro_rules! good_panic {
($($tts:tt)*) => {{
@@ -19,6 +19,87 @@ macro_rules! good_panic {
}}
}
+pub fn logger_formatter_activate(
+ w: &mut dyn std::io::Write,
+ _now: &mut DeferredNow,
+ record: &Record,
+) -> Result<(), std::io::Error> {
+ let level = record.level();
+
+ write!(
+ w,
+ "⭐ REMOTE ⭐ {0} {1} {0} {2}",
+ match level {
+ log::Level::Error => "❌",
+ log::Level::Warn => "⚠️",
+ log::Level::Info => "ℹ️",
+ log::Level::Debug => "❓",
+ log::Level::Trace => "🖊️",
+ },
+ style(level, level.to_string()),
+ record.args()
+ )
+}
+
+pub fn logger_formatter_deploy(
+ w: &mut dyn std::io::Write,
+ _now: &mut DeferredNow,
+ record: &Record,
+) -> Result<(), std::io::Error> {
+ let level = record.level();
+
+ write!(
+ w,
+ "🚀 {0} {1} {0} {2}",
+ match level {
+ log::Level::Error => "❌",
+ log::Level::Warn => "⚠️",
+ log::Level::Info => "ℹ️",
+ log::Level::Debug => "❓",
+ log::Level::Trace => "🖊️",
+ },
+ style(level, level.to_string()),
+ record.args()
+ )
+}
+
+pub fn init_logger(
+ debug_logs: bool,
+ log_dir: Option<&str>,
+ activate: bool,
+) -> Result<(), FlexiLoggerError> {
+ let logger_formatter = match activate {
+ true => logger_formatter_activate,
+ false => logger_formatter_deploy,
+ };
+
+ if let Some(log_dir) = log_dir {
+ Logger::with_env_or_str("debug")
+ .log_to_file()
+ .format_for_stderr(logger_formatter)
+ .set_palette("196;208;51;7;8".to_string())
+ .directory(log_dir)
+ .discriminant(if activate { "activate" } else { "deploy" })
+ .duplicate_to_stderr(match debug_logs {
+ true => Duplicate::Debug,
+ false => Duplicate::Info,
+ })
+ .print_message()
+ .start()?;
+ } else {
+ Logger::with_env_or_str(match debug_logs {
+ true => "debug",
+ false => "info",
+ })
+ .log_target(LogTarget::StdErr)
+ .format(logger_formatter_deploy)
+ .set_palette("196;208;51;7;8".to_string())
+ .start()?;
+ }
+
+ Ok(())
+}
+
pub mod data;
pub mod deploy;
pub mod push;
@@ -191,6 +272,9 @@ pub struct DeployData<'a> {
pub cmd_overrides: &'a CmdOverrides,
pub merged_settings: data::GenericSettings,
+
+ pub debug_logs: bool,
+ pub log_dir: Option<&'a str>,
}
#[derive(Debug)]
@@ -259,6 +343,8 @@ pub fn make_deploy_data<'a, 's>(
profile: &'a data::Profile,
profile_name: &'a str,
cmd_overrides: &'a CmdOverrides,
+ debug_logs: bool,
+ log_dir: Option<&'a str>,
) -> DeployData<'a> {
let mut merged_settings = top_settings.clone();
merged_settings.merge(node.generic_settings.clone());
@@ -292,6 +378,9 @@ pub fn make_deploy_data<'a, 's>(
cmd_overrides,
merged_settings,
+
+ debug_logs,
+ log_dir,
}
}