tikz-gallery-generator
Custum build of stapix for tikz.pablopie.xyz
| Name | Size | Mode |
| .. | ||
| src/log.rs | 2K | -rw-r--r-- |
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105
//! Macros and functions for logging. //! //! This implementation is NOT thread safe: the only logging which does not //! happen on the main thread are thumbnail rendering error, which do not //! require synchronization because they happen right before the entire //! application is killed. use std::{fmt::{Display, Arguments}, time::Duration}; const BOLD_RED: &str = "\u{001b}[1;31m"; const BOLD_GREEN: &str = "\u{001b}[1;32m"; const BOLD_YELLOW: &str = "\u{001b}[1;33m"; const BOLD_BLUE: &str = "\u{001b}[1;34m"; const BOLD_WHITE: &str = "\u{001b}[1;37m"; const RESET: &str = "\u{001b}[0m"; const PROGRAM_VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(Clone, Copy, Debug)] pub(crate) enum Level { Error, Info, Warn, } #[macro_export] macro_rules! infoln { // infoln!("a {} event", "log"); ($($arg:tt)+) => ({ $crate::log::log( $crate::log::Level::Info, &std::format_args!($($arg)+), ); }); } #[macro_export] macro_rules! errorln { // errorln!("a {} event", "log"); ($($arg:tt)+) => ({ $crate::log::log( $crate::log::Level::Error, &std::format_args!($($arg)+), ); }); } #[macro_export] macro_rules! warnln { // warnln!("a {} event", "log"); ($($arg:tt)+) => ({ $crate::log::log( $crate::log::Level::Warn, &std::format_args!($($arg)+), ); }); } pub fn finished(duration: Duration) { let millis = duration.as_millis(); println!(" {BOLD_GREEN}Finished{RESET} Rendering took {millis}ms"); } #[cfg(target_arch = "x86_64")] pub fn version(program_name: &str) { if is_x86_feature_detected!("ssse3") { infoln!("Running {BOLD_WHITE}{program_name} {PROGRAM_VERSION}{RESET} (SIMD optimizations enabled)"); } else { infoln!("Running {BOLD_WHITE}{program_name} {PROGRAM_VERSION}{RESET}"); } } #[cfg(not(target_arch = "x86_64"))] pub fn version(program_name: &str) { infoln!("Running {BOLD_WHITE}{program_name} {PROGRAM_VERSION}{RESET}"); } pub fn usage(program: &str) { use crate::{FULL_BUILD_OPT, N_THREADS_OPT}; println!(" {BOLD_YELLOW}Usage{RESET} {program} [{FULL_BUILD_OPT}] [{N_THREADS_OPT} <jobs>] <config.yml>"); } pub fn usage_config() { println!(" {BOLD_YELLOW}Usage{RESET} See `examples/config.yaml` for an example of configuration file"); } /// Logs the fact a rendering job just finished pub fn job_finished<T: Display + ?Sized>(job_name: &T) { println!(" {BOLD_GREEN}Rendered{RESET} {job_name}"); } pub(crate) fn log(level: Level, args: &Arguments<'_>) { match level { Level::Error => { eprintln!(" {BOLD_RED}Error{RESET} {args}"); } Level::Info => { println!(" {BOLD_BLUE}Info{RESET} {args}"); } Level::Warn => { println!(" {BOLD_YELLOW}Warning{RESET} {args}"); } } }