2020-03-27 17:26:31 +00:00
|
|
|
#![crate_name = "lang_evolve_core"]
|
|
|
|
|
|
|
|
//! # LangEvolveCore
|
|
|
|
//!
|
|
|
|
//! `lang_evolve_core` is the core crate used by two other crates:
|
|
|
|
//! `lang_evolve_cli` and `lang_evolve_gui`.
|
|
|
|
//!
|
|
|
|
//! # What it does
|
|
|
|
//!
|
|
|
|
//! LangEvolveCore is the crate that hosts all the core logic behind LangEvolve,
|
|
|
|
//! a conlanging software developped after the
|
|
|
|
//! [original software](https://github.com/ceronyon/LangEvolve) which applies
|
|
|
|
//! user-defined sound changes to words and texts based on regex expressions.
|
|
|
|
|
2020-03-26 19:10:07 +00:00
|
|
|
use std::fs::File;
|
|
|
|
extern crate log;
|
|
|
|
extern crate simplelog;
|
|
|
|
use log::{info, warn};
|
|
|
|
use simplelog::*;
|
|
|
|
|
2020-03-27 17:25:20 +00:00
|
|
|
pub mod settings;
|
2020-04-04 20:44:08 +00:00
|
|
|
mod utils;
|
2020-03-26 19:10:07 +00:00
|
|
|
|
2020-03-27 17:26:31 +00:00
|
|
|
/// Initializes the crate
|
|
|
|
///
|
|
|
|
/// # What it does
|
|
|
|
///
|
|
|
|
/// Initializing the crate allows to initialize its logging system. All its logs
|
|
|
|
/// will be written to the file `core.log` while the errors will also be shown
|
|
|
|
/// in the terminal.
|
|
|
|
///
|
|
|
|
/// # Return type
|
|
|
|
///
|
|
|
|
/// This function returns a null object if it succeeds. However, if it does not,
|
|
|
|
/// it will send a `log::SetLoggerError` back.
|
|
|
|
///
|
|
|
|
/// # Example usage
|
|
|
|
///
|
|
|
|
/// Its usage is extremely simple, just call it before you do anything with it:
|
|
|
|
/// ```
|
|
|
|
/// lang_evolve_core::init();
|
|
|
|
/// ```
|
2020-03-26 19:10:07 +00:00
|
|
|
pub fn init() -> std::result::Result<(), log::SetLoggerError> {
|
|
|
|
match CombinedLogger::init(vec![
|
|
|
|
TermLogger::new(
|
|
|
|
LevelFilter::Warn,
|
|
|
|
Config::default(),
|
|
|
|
TerminalMode::Mixed,
|
|
|
|
)
|
|
|
|
.unwrap(),
|
2020-04-04 13:46:29 +00:00
|
|
|
WriteLogger::new(
|
|
|
|
LevelFilter::Debug,
|
|
|
|
Config::default(),
|
|
|
|
File::create("core.log").unwrap(),
|
|
|
|
),
|
2020-03-26 19:10:07 +00:00
|
|
|
WriteLogger::new(
|
|
|
|
LevelFilter::Info,
|
|
|
|
Config::default(),
|
|
|
|
File::create("core.log").unwrap(),
|
|
|
|
),
|
|
|
|
]) {
|
|
|
|
Err(why) => {
|
|
|
|
warn!("Could not initialize logger: {}", why.to_string());
|
|
|
|
Err(why)
|
|
|
|
}
|
|
|
|
Ok(_) => {
|
|
|
|
info!("Logger initialized");
|
|
|
|
Ok(())
|
|
|
|
}
|
2020-03-26 16:04:23 +00:00
|
|
|
}
|
|
|
|
}
|