mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
logging
This commit is contained in:
parent
c27b226d4d
commit
2fd692c24d
|
@ -7,3 +7,5 @@ edition = "2021"
|
||||||
glium = "0.32"
|
glium = "0.32"
|
||||||
glutin = "*"
|
glutin = "*"
|
||||||
image = { version = "0.24", default_features = false, features = ["png"] }
|
image = { version = "0.24", default_features = false, features = ["png"] }
|
||||||
|
log = "0.4"
|
||||||
|
env_logger = "0.10"
|
||||||
|
|
|
@ -11,9 +11,13 @@ use assets::Assets;
|
||||||
use display::init_display;
|
use display::init_display;
|
||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
|
log::info!("starting up");
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
log::info!("initializing display");
|
||||||
let display = init_display(&event_loop);
|
let display = init_display(&event_loop);
|
||||||
|
log::info!("loading assets");
|
||||||
let assets = Assets::load_all_sync(&display);
|
let assets = Assets::load_all_sync(&display);
|
||||||
|
log::info!("game loaded");
|
||||||
|
|
||||||
event_loop.run(move |ev, _, control_flow| {
|
event_loop.run(move |ev, _, control_flow| {
|
||||||
match ev {
|
match ev {
|
||||||
|
|
|
@ -2,6 +2,8 @@ use std::{fs, io};
|
||||||
use glium::texture::{RawImage2d, SrgbTexture2d};
|
use glium::texture::{RawImage2d, SrgbTexture2d};
|
||||||
|
|
||||||
fn load_png(file_path: &str, display: &glium::Display) -> SrgbTexture2d {
|
fn load_png(file_path: &str, display: &glium::Display) -> SrgbTexture2d {
|
||||||
|
log::info!("loading texture {}", file_path);
|
||||||
|
|
||||||
//Load file
|
//Load file
|
||||||
let data = fs::read(file_path)
|
let data = fs::read(file_path)
|
||||||
.expect(&format!("Failed to load texture: {}", file_path));
|
.expect(&format!("Failed to load texture: {}", file_path));
|
||||||
|
|
45
src/logging.rs
Normal file
45
src/logging.rs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
//! Custom env_logger options and styling
|
||||||
|
|
||||||
|
use env_logger::{fmt::Color, Builder, Env};
|
||||||
|
use log::Level;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
let mut env = Env::default();
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
env = env.filter_or("RUST_LOG", "info");
|
||||||
|
}
|
||||||
|
Builder::from_env(env)
|
||||||
|
.format(|buf, record| {
|
||||||
|
let mut level_style = buf.style();
|
||||||
|
level_style.set_color(match record.level() {
|
||||||
|
Level::Error => Color::Red,
|
||||||
|
Level::Warn => Color::Yellow,
|
||||||
|
_ => Color::Blue
|
||||||
|
}).set_bold(true);
|
||||||
|
|
||||||
|
let mut location_style = buf.style();
|
||||||
|
location_style.set_bold(true);
|
||||||
|
location_style.set_dimmed(true);
|
||||||
|
|
||||||
|
let mut location_line_style = buf.style();
|
||||||
|
location_line_style.set_dimmed(true);
|
||||||
|
|
||||||
|
writeln!(
|
||||||
|
buf,
|
||||||
|
"{} {:<50}\t{}{}{}",
|
||||||
|
level_style.value(match record.level() {
|
||||||
|
Level::Error => "[e]",
|
||||||
|
Level::Warn => "[w]",
|
||||||
|
Level::Info => "[i]",
|
||||||
|
Level::Debug => "[d]",
|
||||||
|
Level::Trace => "[t]",
|
||||||
|
}),
|
||||||
|
format!("{}", record.args()),
|
||||||
|
location_style.value(record.module_path().unwrap_or("<unknown>")),
|
||||||
|
location_line_style.value(" :"),
|
||||||
|
location_line_style.value(record.line().unwrap_or(0))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.init();
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
mod game;
|
mod game;
|
||||||
|
mod logging;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
logging::init();
|
||||||
game::run();
|
game::run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue