1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
pub extern crate glob;
pub extern crate tempfile;
pub mod app_root_dir;
pub mod clipboard;
#[cfg(feature = "file_dialog")]
pub mod dialog;
pub mod finder;
#[cfg(feature = "git")]
pub mod git_cmd;
#[cfg(feature = "html")]
pub mod html_scraping;
#[cfg(feature = "image_processing")]
pub mod img_processing;
#[cfg(feature = "ldap")]
pub mod ldap;
#[cfg(feature = "python")]
pub mod py;
#[cfg(feature = "sound")]
pub mod sound;
pub mod text;
pub mod uploader;
pub mod version;
#[cfg(feature = "web_client")]
pub mod web;
pub use uploader::{CopyOp, FileCopySpec, TemplateFile};
use anyhow::{anyhow, Result as AnyResult};
#[cfg(feature = "fern_log")]
use fern::colors::{Color, ColoredLevelConfig};
pub use log::{debug, error, info, warn};
use serde::Deserialize;
use std::path::{Path, PathBuf};
#[cfg(feature = "fern_log")]
pub fn setup_logger(level: log::LevelFilter) -> Result<fern::Dispatch, fern::InitError> {
let colors = ColoredLevelConfig::new()
.error(Color::Red)
.warn(Color::Yellow)
.info(Color::Green)
.debug(Color::Blue);
Ok(fern::Dispatch::new()
.format(move |out, message, record| {
out.finish(format_args!(
"{}[{}][{}] {}",
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
record.target(),
colors.color(record.level()),
message
))
})
.level(level)
.level_for("mkutil::finder", log::LevelFilter::Info)
.level_for("html5ever", log::LevelFilter::Warn)
.level_for("naga", log::LevelFilter::Info)
.level_for("wgpu_core", log::LevelFilter::Warn)
.level_for("wgpu_hal", log::LevelFilter::Warn)
.chain(std::io::stdout()))
}
#[cfg(feature = "fern_log")]
pub fn apply_fern_log(level: log::LevelFilter) {
let logger = setup_logger(level).unwrap();
logger.apply().unwrap();
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn get_app_root_dir() {
let root_dir = app_root_dir::application_root_dir();
eprintln!("App root dir: {:?}", root_dir);
assert!(root_dir.is_ok());
}
}