lang-evolve-core/src/lib.rs

72 lines
1.9 KiB
Rust

#![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.
use std::fs::File;
extern crate log;
extern crate simplelog;
use log::{info, warn};
use simplelog::*;
pub mod settings;
pub mod utils;
/// 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();
/// ```
pub fn init() -> std::result::Result<(), log::SetLoggerError> {
match CombinedLogger::init(vec![
TermLogger::new(
LevelFilter::Warn,
Config::default(),
TerminalMode::Mixed,
)
.unwrap(),
WriteLogger::new(
LevelFilter::Debug,
Config::default(),
File::create("core.log").unwrap(),
),
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(())
}
}
}