Skip to content

Commit

Permalink
move to tracing crate, but the .log file is weird looking now
Browse files Browse the repository at this point in the history
  • Loading branch information
gillett-hernandez committed May 23, 2024
1 parent c29a8b3 commit d5458ba
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 113 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ egui_extras = { version = "~0", optional = true }
egui_plot = { version = "~0", optional = true }
exr = "~1.72"
image = { version = "~0.25", features = ["hdr"] }
log = "~0.4"
log-once = "~0.4"
# log = "~0.4"
# log-once = "~0.4"
lazy_static = "~1.4"
math = { git = "https://github.com/gillett-hernandez/rust_cg_math", features = [
"serde",
"deepsize",
Expand All @@ -55,12 +56,13 @@ rayon = "~1.10"
rust_optics = { git = "https://github.com/gillett-hernandez/rust_optics", optional = true }
sdfu = { git = "https://github.com/fu5ha/sdfu", optional = true }
serde = { version = "~1.0", features = ["derive"] }
simplelog = "0.12"
# simplelog = "0.12"
smallvec = "~1.13"
structopt = "~0.3"
tobj = "~4.0"
toml = "~0.8"
tracing = "~0.1"
tracing-subscriber = "~0.3"
ultraviolet = { version = "~0.8", optional = true }

[target.'cfg(windows)'.dependencies]
Expand Down
28 changes: 11 additions & 17 deletions src/bin/color_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extern crate rust_pathtracer as root;
use parking_lot::RwLock;
use root::{prelude::*, update_window_buffer};
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

use std::ops::RangeInclusive;
use std::{fs::File, sync::Arc};
Expand All @@ -13,14 +15,12 @@ use root::parsing::*;
use root::tonemap::Tonemapper;

#[macro_use]
extern crate log;
extern crate tracing;

use crossbeam::channel::{unbounded, Receiver, Sender};
use eframe::egui;
use log::LevelFilter;
use minifb::{Key, KeyRepeat, Scale, Window, WindowOptions};
use rayon::iter::ParallelIterator;
use simplelog::{ColorChoice, CombinedLogger, TermLogger, TerminalMode, WriteLogger};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -597,20 +597,14 @@ fn mvc(opts: Opt) -> Result<(Model, Controller), ()> {
}

fn main() {
CombinedLogger::init(vec![
TermLogger::new(
LevelFilter::Warn,
simplelog::Config::default(),
TerminalMode::Mixed,
ColorChoice::Auto,
),
WriteLogger::new(
LevelFilter::Info,
simplelog::Config::default(),
File::create("color_test.log").unwrap(),
),
])
.unwrap();
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::TRACE)
// completes the builder.
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let opts = Opt::from_args();

Expand Down
67 changes: 39 additions & 28 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![feature(fs_try_exists)]
extern crate rust_pathtracer as root;

use log::LevelFilter;
use root::parsing::cameras::parse_config_and_cameras;
// use root::prelude::*;
use root::parsing::config::*;
Expand All @@ -15,10 +14,11 @@ use root::renderer::PreviewRenderer;
use root::world::*;

#[macro_use]
extern crate log;
extern crate tracing;

// use simplelog::*;
use simplelog::{ColorChoice, CombinedLogger, TermLogger, TerminalMode, WriteLogger};
use tracing::level_filters::LevelFilter;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

use std::fs;
use std::fs::File;
Expand All @@ -41,7 +41,7 @@ struct Opt {
#[structopt(short = "n", long)]
pub dry_run: bool,
#[structopt(short = "pll", long, default_value = "warn")]
pub print_log_level: String,
pub stdout_log_level: String,
#[structopt(short = "wll", long, default_value = "info")]
pub write_log_level: String,
}
Expand All @@ -61,36 +61,47 @@ fn construct_renderer(config: &Config) -> Box<dyn Renderer> {
}
}

fn parse_log_level(level: String, default: LevelFilter) -> LevelFilter {
fn parse_level_filter(level: String, default: LevelFilter) -> LevelFilter {
match level.to_lowercase().as_str() {
"warn" => LevelFilter::Warn,
"info" => LevelFilter::Info,
"trace" => LevelFilter::Trace,
"error" => LevelFilter::Error,
"debug" => LevelFilter::Debug,
"warn" => LevelFilter::WARN,
"info" => LevelFilter::INFO,
"trace" => LevelFilter::TRACE,
"error" => LevelFilter::ERROR,
"debug" => LevelFilter::DEBUG,
_ => default,
}
}

fn main() {
let opts = Opt::from_args();
let term_log_level = parse_log_level(opts.print_log_level, LevelFilter::Warn);
let write_log_level = parse_log_level(opts.write_log_level, LevelFilter::Info);

CombinedLogger::init(vec![
TermLogger::new(
term_log_level,
simplelog::Config::default(),
TerminalMode::Mixed,
ColorChoice::Auto,
),
WriteLogger::new(
write_log_level,
simplelog::Config::default(),
File::create("main.log").unwrap(),
),
])
.unwrap();
let stdout_log_level = parse_level_filter(opts.stdout_log_level, LevelFilter::WARN);
let write_log_level = parse_level_filter(opts.write_log_level, LevelFilter::INFO);

use std::{fs::File, sync::Arc};
use tracing_subscriber::prelude::*;

// A layer that logs events to stdout using the human-readable "pretty"
// format.
let stdout_log = tracing_subscriber::fmt::layer().pretty();

// A layer that logs events to a file.
let file = File::create("main.log").unwrap();
let write_log = tracing_subscriber::fmt::layer().with_writer(Arc::new(file));

tracing_subscriber::registry()
.with(stdout_log.with_filter(stdout_log_level))
.with(write_log.with_filter(write_log_level))
.init();

// // a builder for `FmtSubscriber`.
// let subscriber = FmtSubscriber::builder()
// // all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
// // will be written to stdout.
// .with_max_level(stdout_log_level)
// // completes the builder.
// .finish();

// tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let mut cache_path = PathBuf::new();
cache_path.push(".");
Expand Down
39 changes: 19 additions & 20 deletions src/bin/raymarch.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#![feature(portable_simd)]
extern crate rust_pathtracer as root;
#[macro_use]
extern crate tracing;

// std imports
use std::cmp::Ordering;
use std::fs::File;

// third party but non-subject-matter imports
use log::LevelFilter;
use log_once::warn_once;
#[cfg(feature = "preview")]
use minifb::WindowOptions;
use pbr::ProgressBar;
use rayon::iter::ParallelIterator;
use simplelog::{ColorChoice, CombinedLogger, TermLogger, TerminalMode, WriteLogger};
use structopt::StructOpt;

// our imports
Expand All @@ -29,6 +27,8 @@ use root::world::{EnvironmentMap, Material, MaterialEnum};
// third party but subject-matter-relevant imports
use sdfu::ops::{HardMin, Union};
use sdfu::SDF;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
use ultraviolet::vec::Vec3 as uvVec3;

trait Convert {
Expand Down Expand Up @@ -352,7 +352,13 @@ impl<S: SDF<f32, uvVec3> + MaterialTag> Scene<S> {
}
}
None => {
warn_once!("didn't bounce");
lazy_static! {
static ref LOGGED_CELL: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);
}
if !LOGGED_CELL.fetch_or(true, std::sync::atomic::Ordering::AcqRel) {
warn!("didn't bounce");
}
break;
}
}
Expand Down Expand Up @@ -389,21 +395,14 @@ macro_rules! find_and_add_material {
}

fn main() {
CombinedLogger::init(vec![
TermLogger::new(
LevelFilter::Warn,
simplelog::Config::default(),
TerminalMode::Mixed,
ColorChoice::Auto,
),
WriteLogger::new(
LevelFilter::Info,
simplelog::Config::default(),
File::create("main.log").unwrap(),
),
])
.unwrap();

let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::TRACE)
// completes the builder.
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let opt = Opt::from_args();

let settings = get_settings(opt.config).unwrap();
Expand Down
17 changes: 14 additions & 3 deletions src/camera/realistic_camera.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::prelude::*;

use crate::geometry::*;
use log_once::warn_once;
use optics::aperture::{Aperture, ApertureEnum};
use optics::{lens_sampler::RadialSampler, Input, LensAssembly, LensInterface, Output};

Expand Down Expand Up @@ -184,7 +183,13 @@ impl Camera<f32, f32> for RealisticCamera {
if let Some(r) = result {
r
} else {
warn_once!("failed to sample ray, returning ray with tau/pdf 0");
lazy_static! {
static ref LOGGED_CELL: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);
}
if !LOGGED_CELL.fetch_or(true, std::sync::atomic::Ordering::AcqRel) {
warn!("failed to sample ray, returning ray with tau/pdf 0");
}
(Ray::new(central_point, Vec3::Z), 0.0)
}
}
Expand All @@ -199,7 +204,13 @@ impl Camera<f32, f32> for RealisticCamera {
todo!();
}

fn eval_we(&self, _lambda: f32, _normal: Vec3, _from: Point3, _to: Point3) -> (f32, PDF<f32, SolidAngle>) {
fn eval_we(
&self,
_lambda: f32,
_normal: Vec3,
_from: Point3,
_to: Point3,
) -> (f32, PDF<f32, SolidAngle>) {
// TODO implement We, requires backwards tracing to be robust
todo!()
}
Expand Down
8 changes: 6 additions & 2 deletions src/geometry/rect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::prelude::*;
use log_once::warn_once;

use crate::aabb::{HasBoundingBox, AABB};
use crate::hittable::{HitRecord, Hittable};
Expand Down Expand Up @@ -126,7 +125,12 @@ impl Hittable for AARect {
let pdf = area_pdf.convert_to_solid_angle(cos_i, direction.norm_squared());

if !pdf.is_finite() || pdf.is_nan() {
warn_once!("pdf was inf or nan, {:?}, {:?}", direction, cos_i);
lazy_static! {
static ref LOGGED_CELL: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
}
if !LOGGED_CELL.fetch_or(true, std::sync::atomic::Ordering::AcqRel) {
warn!("pdf was inf or nan, {:?}, {:?}", direction, cos_i);
}
(direction.normalized(), 0.0.into())
} else {
(direction.normalized(), pdf)
Expand Down
17 changes: 10 additions & 7 deletions src/geometry/sphere.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::prelude::*;
use log_once::warn_once;

use crate::aabb::{HasBoundingBox, AABB};
use crate::hittable::{HitRecord, Hittable};
Expand Down Expand Up @@ -114,12 +113,16 @@ impl Hittable for Sphere {
let pdf: PDF<f32, SolidAngle> =
PDF::new(*area_pdf * direction.norm_squared() / normal_dot_direction);
if !(*pdf).is_finite() {
warn_once!(
"pdf was inf, {:?}, area_pdf: {:?}, n * d: {:?}",
pdf,
area_pdf,
normal_dot_direction,
);
lazy_static! {
static ref LOGGED_CELL: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);
}
if !LOGGED_CELL.fetch_or(true, std::sync::atomic::Ordering::AcqRel) {
warn!(
"pdf was inf, {:?}, area_pdf: {:?}, n * d: {:?}",
pdf, area_pdf, normal_dot_direction,
);
}

(direction.normalized(), 0.0.into())
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/integrator/lt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use log_once::warn_once;

use crate::world::World;
// use crate::config::Settings;
Expand Down Expand Up @@ -302,7 +301,12 @@ impl GenericIntegrator for LightTracingIntegrator {
}
}
VertexType::LightSource(_) => {
warn_once!("hit light source while doing light tracing");
lazy_static! {
static ref LOGGED_CELL: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
}
if !LOGGED_CELL.fetch_or(true, std::sync::atomic::Ordering::AcqRel) {
warn!("hit light source while doing light tracing");
}
// could potentially add energy to the path if light sources are hit while tracing
}
VertexType::Eye => unreachable!(),
Expand Down
20 changes: 12 additions & 8 deletions src/integrator/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{mediums::MediumEnum, prelude::*};

use log_once::warn_once;

use crate::hittable::HitRecord;
use crate::mediums::Medium;
Expand Down Expand Up @@ -231,13 +230,18 @@ pub fn random_walk<L, E>(
let cos_i = wi.z().abs();
vertex.veach_g = veach_g(hit.point, cos_i, ray.origin, cos_o);
if !vertex.veach_g.is_finite() {
warn_once!(
"veach g was inf, {:?} {:?} {} {}",
hit.point,
ray.origin,
cos_i,
cos_o
);
lazy_static! {
static ref LOGGED_CELL: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
}
if !LOGGED_CELL.fetch_or(true, std::sync::atomic::Ordering::AcqRel) {
warn!(
"veach g was inf, {:?} {:?} {} {}",
hit.point,
ray.origin,
cos_i,
cos_o
);
}
}

if !matches!(
Expand Down
Loading

0 comments on commit d5458ba

Please sign in to comment.