fix(core): change trace log format

This commit is contained in:
Federico Terzi 2021-04-17 13:31:45 +02:00
parent 3a51efda2c
commit 799474a0fc

View File

@ -23,7 +23,9 @@ extern crate lazy_static;
use clap::{App, AppSettings, Arg, SubCommand}; use clap::{App, AppSettings, Arg, SubCommand};
use cli::{CliModule, CliModuleArgs}; use cli::{CliModule, CliModuleArgs};
use logging::FileProxy; use logging::FileProxy;
use simplelog::{CombinedLogger, ConfigBuilder, LevelFilter, TermLogger, TerminalMode, WriteLogger}; use simplelog::{
CombinedLogger, ConfigBuilder, LevelFilter, TermLogger, TerminalMode, WriteLogger,
};
mod cli; mod cli;
mod engine; mod engine;
@ -33,11 +35,8 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
const LOG_FILE_NAME: &str = "espanso.log"; const LOG_FILE_NAME: &str = "espanso.log";
lazy_static! { lazy_static! {
static ref CLI_HANDLERS: Vec<CliModule> = vec![ static ref CLI_HANDLERS: Vec<CliModule> =
cli::path::new(), vec![cli::path::new(), cli::log::new(), cli::worker::new(),];
cli::log::new(),
cli::worker::new(),
];
} }
fn main() { fn main() {
@ -73,126 +72,133 @@ fn main() {
.arg(Arg::with_name("package_name").help("Package name")); .arg(Arg::with_name("package_name").help("Package name"));
let mut clap_instance = App::new("espanso") let mut clap_instance = App::new("espanso")
.version(VERSION) .version(VERSION)
.author("Federico Terzi") .author("Federico Terzi")
.about("A Privacy-first, Cross-platform Text Expander") .about("A Privacy-first, Cross-platform Text Expander")
.arg(Arg::with_name("v") .arg(
.short("v") Arg::with_name("v")
.multiple(true) .short("v")
.help("Sets the level of verbosity")) .multiple(true)
// .subcommand(SubCommand::with_name("cmd") .help("Sets the level of verbosity"),
// .about("Send a command to the espanso daemon.") )
// .subcommand(SubCommand::with_name("exit") // .subcommand(SubCommand::with_name("cmd")
// .about("Terminate the daemon.")) // .about("Send a command to the espanso daemon.")
// .subcommand(SubCommand::with_name("enable") // .subcommand(SubCommand::with_name("exit")
// .about("Enable the espanso replacement engine.")) // .about("Terminate the daemon."))
// .subcommand(SubCommand::with_name("disable") // .subcommand(SubCommand::with_name("enable")
// .about("Disable the espanso replacement engine.")) // .about("Enable the espanso replacement engine."))
// .subcommand(SubCommand::with_name("toggle") // .subcommand(SubCommand::with_name("disable")
// .about("Toggle the status of the espanso replacement engine.")) // .about("Disable the espanso replacement engine."))
// ) // .subcommand(SubCommand::with_name("toggle")
// .subcommand(SubCommand::with_name("edit") // .about("Toggle the status of the espanso replacement engine."))
// .about("Open the default text editor to edit config files and reload them automatically when exiting") // )
// .arg(Arg::with_name("config") // .subcommand(SubCommand::with_name("edit")
// .help("Defaults to \"default\". The configuration file name to edit (without the .yml extension).")) // .about("Open the default text editor to edit config files and reload them automatically when exiting")
// .arg(Arg::with_name("norestart") // .arg(Arg::with_name("config")
// .short("n") // .help("Defaults to \"default\". The configuration file name to edit (without the .yml extension)."))
// .long("norestart") // .arg(Arg::with_name("norestart")
// .required(false) // .short("n")
// .takes_value(false) // .long("norestart")
// .help("Avoid restarting espanso after editing the file")) // .required(false)
// ) // .takes_value(false)
// .subcommand(SubCommand::with_name("detect") // .help("Avoid restarting espanso after editing the file"))
// .about("Tool to detect current window properties, to simplify filters creation.")) // )
// .subcommand(SubCommand::with_name("daemon") // .subcommand(SubCommand::with_name("detect")
// .about("Start the daemon without spawning a new process.")) // .about("Tool to detect current window properties, to simplify filters creation."))
// .subcommand(SubCommand::with_name("register") // .subcommand(SubCommand::with_name("daemon")
// .about("MacOS and Linux only. Register espanso in the system daemon manager.")) // .about("Start the daemon without spawning a new process."))
// .subcommand(SubCommand::with_name("unregister") // .subcommand(SubCommand::with_name("register")
// .about("MacOS and Linux only. Unregister espanso from the system daemon manager.")) // .about("MacOS and Linux only. Register espanso in the system daemon manager."))
.subcommand(SubCommand::with_name("log") // .subcommand(SubCommand::with_name("unregister")
.about("Print the daemon logs.")) // .about("MacOS and Linux only. Unregister espanso from the system daemon manager."))
// .subcommand(SubCommand::with_name("start") .subcommand(SubCommand::with_name("log").about("Print the daemon logs."))
// .about("Start the daemon spawning a new process in the background.")) // .subcommand(SubCommand::with_name("start")
// .subcommand(SubCommand::with_name("stop") // .about("Start the daemon spawning a new process in the background."))
// .about("Stop the espanso daemon.")) // .subcommand(SubCommand::with_name("stop")
// .subcommand(SubCommand::with_name("restart") // .about("Stop the espanso daemon."))
// .about("Restart the espanso daemon.")) // .subcommand(SubCommand::with_name("restart")
// .subcommand(SubCommand::with_name("status") // .about("Restart the espanso daemon."))
// .about("Check if the espanso daemon is running or not.")) // .subcommand(SubCommand::with_name("status")
.subcommand(SubCommand::with_name("path") // .about("Check if the espanso daemon is running or not."))
.about("Prints all the espanso directory paths to easily locate configuration and matches.") .subcommand(
.subcommand(SubCommand::with_name("config") SubCommand::with_name("path")
.about("Print the current config folder path.")) .about("Prints all the espanso directory paths to easily locate configuration and matches.")
.subcommand(SubCommand::with_name("packages") .subcommand(SubCommand::with_name("config").about("Print the current config folder path."))
.about("Print the current packages folder path.")) .subcommand(
.subcommand(SubCommand::with_name("data") SubCommand::with_name("packages").about("Print the current packages folder path."),
.about("Print the current data folder path.")
.setting(AppSettings::Hidden)) // Legacy path
.subcommand(SubCommand::with_name("runtime")
.about("Print the current runtime folder path."))
.subcommand(SubCommand::with_name("default")
.about("Print the default configuration file path."))
.subcommand(SubCommand::with_name("base")
.about("Print the default match file path."))
) )
// .subcommand(SubCommand::with_name("match") .subcommand(
// .about("List and execute matches from the CLI") SubCommand::with_name("data")
// .subcommand(SubCommand::with_name("list") .about("Print the current data folder path.")
// .about("Print all matches to standard output") .setting(AppSettings::Hidden),
// .arg(Arg::with_name("json") ) // Legacy path
// .short("j") .subcommand(
// .long("json") SubCommand::with_name("runtime").about("Print the current runtime folder path."),
// .help("Return the matches as json") )
// .required(false) .subcommand(
// .takes_value(false) SubCommand::with_name("default").about("Print the default configuration file path."),
// ) )
// .arg(Arg::with_name("onlytriggers") .subcommand(SubCommand::with_name("base").about("Print the default match file path.")),
// .short("t") )
// .long("onlytriggers") // .subcommand(SubCommand::with_name("match")
// .help("Print only triggers without replacement") // .about("List and execute matches from the CLI")
// .required(false) // .subcommand(SubCommand::with_name("list")
// .takes_value(false) // .about("Print all matches to standard output")
// ) // .arg(Arg::with_name("json")
// .arg(Arg::with_name("preservenewlines") // .short("j")
// .short("n") // .long("json")
// .long("preservenewlines") // .help("Return the matches as json")
// .help("Preserve newlines when printing replacements") // .required(false)
// .required(false) // .takes_value(false)
// .takes_value(false) // )
// ) // .arg(Arg::with_name("onlytriggers")
// ) // .short("t")
// .subcommand(SubCommand::with_name("exec") // .long("onlytriggers")
// .about("Triggers the expansion of the given match") // .help("Print only triggers without replacement")
// .arg(Arg::with_name("trigger") // .required(false)
// .help("The trigger of the match to be expanded") // .takes_value(false)
// ) // )
// ) // .arg(Arg::with_name("preservenewlines")
// ) // .short("n")
// Package manager // .long("preservenewlines")
// .subcommand(SubCommand::with_name("package") // .help("Preserve newlines when printing replacements")
// .about("Espanso package manager commands") // .required(false)
// .subcommand(install_subcommand.clone()) // .takes_value(false)
// .subcommand(uninstall_subcommand.clone()) // )
// .subcommand(SubCommand::with_name("list") // )
// .about("List all installed packages") // .subcommand(SubCommand::with_name("exec")
// .arg(Arg::with_name("full") // .about("Triggers the expansion of the given match")
// .help("Print all package info") // .arg(Arg::with_name("trigger")
// .long("full"))) // .help("The trigger of the match to be expanded")
// )
// .subcommand(SubCommand::with_name("refresh") // )
// .about("Update espanso package index")) // )
// ) // Package manager
.subcommand(SubCommand::with_name("worker") // .subcommand(SubCommand::with_name("package")
.setting(AppSettings::Hidden) // .about("Espanso package manager commands")
.arg(Arg::with_name("reload") // .subcommand(install_subcommand.clone())
.short("r") // .subcommand(uninstall_subcommand.clone())
.long("reload") // .subcommand(SubCommand::with_name("list")
.required(false) // .about("List all installed packages")
.takes_value(false)) // .arg(Arg::with_name("full")
); // .help("Print all package info")
// .subcommand(install_subcommand) // .long("full")))
// .subcommand(uninstall_subcommand); // .subcommand(SubCommand::with_name("refresh")
// .about("Update espanso package index"))
// )
.subcommand(
SubCommand::with_name("worker")
.setting(AppSettings::Hidden)
.arg(
Arg::with_name("reload")
.short("r")
.long("reload")
.required(false)
.takes_value(false),
),
);
// .subcommand(install_subcommand)
// .subcommand(uninstall_subcommand);
// TODO: explain that the start and restart commands are only meaningful // TODO: explain that the start and restart commands are only meaningful
// when using the system daemon manager on macOS and Linux // when using the system daemon manager on macOS and Linux
@ -216,7 +222,10 @@ fn main() {
if let Some(handler) = handler { if let Some(handler) = handler {
let log_proxy = FileProxy::new(); let log_proxy = FileProxy::new();
if handler.enable_logs { if handler.enable_logs {
let config = ConfigBuilder::new().set_time_to_local(true).build(); let config = ConfigBuilder::new()
.set_time_to_local(true)
.set_location_level(LevelFilter::Off)
.build();
CombinedLogger::init(vec![ CombinedLogger::init(vec![
TermLogger::new(log_level, config.clone(), TerminalMode::Mixed), TermLogger::new(log_level, config.clone(), TerminalMode::Mixed),