Skip to content

Commit fbb502a

Browse files
committed
Mop up conversion from cerr to clog
Missed SO MANY places where we should use `std::clog` instead of `std::cerr`. - Convert _all_ scanline progress loops and corresponding text. - Convert debugging output to use `std::clog` instead of `std::cerr`, as well as corresponding text.
1 parent b041c92 commit fbb502a

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@
186186

187187
<div class='together'>
188188
Our program outputs the image to the standard output stream (`std::cout`), so leave that alone and
189-
instead write to the error output stream (`std::cerr`):
189+
instead write to the logging output stream (`std::clog`):
190190

191191
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
192192
for (int j = image_height-1; j >= 0; --j) {
193193
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
194-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
194+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
195195
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
196196
for (int i = 0; i < image_width; ++i) {
197197
auto r = double(i) / (image_width-1);
@@ -208,7 +208,7 @@
208208

209209

210210
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
211-
std::cerr << "\nDone.\n";
211+
std::clog << "\nDone.\n";
212212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213213
[Listing [main-progress]: <kbd>[main.cc]</kbd> Main render loop with progress reporting]
214214
</div>
@@ -402,7 +402,7 @@
402402
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
403403

404404
for (int j = image_height-1; j >= 0; --j) {
405-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
405+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
406406
for (int i = 0; i < image_width; ++i) {
407407
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
408408
color pixel_color(double(i)/(image_width-1), double(j)/(image_height-1), 0.25);
@@ -411,7 +411,7 @@
411411
}
412412
}
413413

414-
std::cerr << "\nDone.\n";
414+
std::clog << "\nDone.\n";
415415
}
416416
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
417417
[Listing [ppm-2]: <kbd>[main.cc]</kbd> Final code for the first PPM image]
@@ -548,7 +548,7 @@
548548
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
549549

550550
for (int j = image_height-1; j >= 0; --j) {
551-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
551+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
552552
for (int i = 0; i < image_width; ++i) {
553553
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
554554
auto u = double(i) / (image_width-1);
@@ -560,7 +560,7 @@
560560
}
561561
}
562562

563-
std::cerr << "\nDone.\n";
563+
std::clog << "\nDone.\n";
564564
}
565565
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
566566
[Listing [main-blue-white-blend]: <kbd>[main.cc]</kbd> Rendering a blue-to-white gradient]
@@ -1254,7 +1254,7 @@
12541254
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
12551255

12561256
for (int j = image_height-1; j >= 0; --j) {
1257-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
1257+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
12581258
for (int i = 0; i < image_width; ++i) {
12591259
auto u = double(i) / (image_width-1);
12601260
auto v = double(j) / (image_height-1);
@@ -1266,7 +1266,7 @@
12661266
}
12671267
}
12681268

1269-
std::cerr << "\nDone.\n";
1269+
std::clog << "\nDone.\n";
12701270
}
12711271
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12721272
[Listing [main-with-rtweekend-h]: <kbd>[main.cc]</kbd> The new main with hittables]
@@ -1591,7 +1591,7 @@
15911591
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
15921592

15931593
for (int j = image_height-1; j >= 0; --j) {
1594-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
1594+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
15951595
for (int i = 0; i < image_width; ++i) {
15961596
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
15971597
color pixel_color(0, 0, 0);
@@ -1606,7 +1606,7 @@
16061606
}
16071607
}
16081608

1609-
std::cerr << "\nDone.\n";
1609+
std::clog << "\nDone.\n";
16101610
}
16111611
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16121612
[Listing [main-multi-sample]: <kbd>[main.cc]</kbd> Rendering with multi-sampled pixels]
@@ -1770,7 +1770,7 @@
17701770
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
17711771

17721772
for (int j = image_height-1; j >= 0; --j) {
1773-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
1773+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
17741774
for (int i = 0; i < image_width; ++i) {
17751775
color pixel_color(0, 0, 0);
17761776
for (int s = 0; s < samples_per_pixel; ++s) {
@@ -1785,7 +1785,7 @@
17851785
}
17861786
}
17871787

1788-
std::cerr << "\nDone.\n";
1788+
std::clog << "\nDone.\n";
17891789
}
17901790
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17911791
[Listing [ray-color-depth]: <kbd>[main.cc]</kbd> ray_color() with depth limiting]
@@ -2370,7 +2370,7 @@
23702370
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
23712371

23722372
for (int j = image_height-1; j >= 0; --j) {
2373-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
2373+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
23742374
for (int i = 0; i < image_width; ++i) {
23752375
color pixel_color(0, 0, 0);
23762376
for (int s = 0; s < samples_per_pixel; ++s) {
@@ -2383,7 +2383,7 @@
23832383
}
23842384
}
23852385

2386-
std::cerr << "\nDone.\n";
2386+
std::clog << "\nDone.\n";
23872387
}
23882388
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23892389
[Listing [scene-with-metal]: <kbd>[main.cc]</kbd> Scene with metal spheres]
@@ -2829,7 +2829,7 @@
28292829
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
28302830

28312831
for (int j = image_height-1; j >= 0; --j) {
2832-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
2832+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
28332833
for (int i = 0; i < image_width; ++i) {
28342834
color pixel_color(0,0,0);
28352835
for (int s = 0; s < samples_per_pixel; ++s) {
@@ -2842,7 +2842,7 @@
28422842
}
28432843
}
28442844

2845-
std::cerr << "\nDone.\n";
2845+
std::clog << "\nDone.\n";
28462846
}
28472847

28482848
public:

books/RayTracingTheNextWeek.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,7 +3388,7 @@
33883388
if (!boundary->hit(r, interval(rec1.t+0.0001, infinity), rec2))
33893389
return false;
33903390

3391-
if (debugging) std::cerr << "\nray_tmin=" << rec1.t << ", ray_tmax=" << rec2.t << '\n';
3391+
if (debugging) std::clog << "\nray_tmin=" << rec1.t << ", ray_tmax=" << rec2.t << '\n';
33923392

33933393
if (rec1.t < ray_t.min) rec1.t = ray_t.min;
33943394
if (rec2.t > ray_t.max) rec2.t = ray_t.max;
@@ -3410,7 +3410,7 @@
34103410
rec.p = r.at(rec.t);
34113411

34123412
if (debugging) {
3413-
std::cerr << "hit_distance = " << hit_distance << '\n'
3413+
std::clog << "hit_distance = " << hit_distance << '\n'
34143414
<< "rec.t = " << rec.t << '\n'
34153415
<< "rec.p = " << rec.p << '\n';
34163416
}

books/RayTracingTheRestOfYourLife.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
int sqrt_spp = int(sqrt(samples_per_pixrel));
341341
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
342342
for (int j = image_height-1; j >= 0; --j) {
343-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
343+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
344344
for (int i = 0; i < image_width; ++i) {
345345
color pixel_color(0,0,0);
346346
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
@@ -357,7 +357,7 @@
357357
}
358358
}
359359

360-
std::cerr << "\nDone.\n";
360+
std::clog << "\nDone.\n";
361361
}
362362
}
363363
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/TheNextWeek/constant_medium.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class constant_medium : public hittable {
4141
if (!boundary->hit(r, interval(rec1.t+0.0001, infinity), rec2))
4242
return false;
4343

44-
if (debugging) std::cerr << "\nt_min=" << rec1.t << ", t_max=" << rec2.t << '\n';
44+
if (debugging) std::clog << "\nt_min=" << rec1.t << ", t_max=" << rec2.t << '\n';
4545

4646
if (rec1.t < ray_t.min) rec1.t = ray_t.min;
4747
if (rec2.t > ray_t.max) rec2.t = ray_t.max;
@@ -63,7 +63,7 @@ class constant_medium : public hittable {
6363
rec.p = r.at(rec.t);
6464

6565
if (debugging) {
66-
std::cerr << "hit_distance = " << hit_distance << '\n'
66+
std::clog << "hit_distance = " << hit_distance << '\n'
6767
<< "rec.t = " << rec.t << '\n'
6868
<< "rec.p = " << rec.p << '\n';
6969
}

src/TheNextWeek/scene.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class scene {
2727
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
2828

2929
for (int j = image_height-1; j >= 0; --j) {
30-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
30+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
3131
for (int i = 0; i < image_width; ++i) {
3232
color pixel_color(0,0,0);
3333
for (int s = 0; s < samples_per_pixel; ++s) {
@@ -40,7 +40,7 @@ class scene {
4040
}
4141
}
4242

43-
std::cerr << "\nDone.\n";
43+
std::clog << "\nDone.\n";
4444
}
4545

4646
public:

src/TheRestOfYourLife/constant_medium.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class constant_medium : public hittable {
4141
if (!boundary->hit(r, interval(rec1.t+0.0001, infinity), rec2))
4242
return false;
4343

44-
if (debugging) std::cerr << "\nt_min=" << rec1.t << ", t_max=" << rec2.t << '\n';
44+
if (debugging) std::clog << "\nt_min=" << rec1.t << ", t_max=" << rec2.t << '\n';
4545

4646
if (rec1.t < ray_t.min) rec1.t = ray_t.min;
4747
if (rec2.t > ray_t.max) rec2.t = ray_t.max;
@@ -63,7 +63,7 @@ class constant_medium : public hittable {
6363
rec.p = r.at(rec.t);
6464

6565
if (debugging) {
66-
std::cerr << "hit_distance = " << hit_distance << '\n'
66+
std::clog << "hit_distance = " << hit_distance << '\n'
6767
<< "rec.t = " << rec.t << '\n'
6868
<< "rec.p = " << rec.p << '\n';
6969
}

src/TheRestOfYourLife/scene.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class scene {
2525
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
2626

2727
for (int j = image_height-1; j >= 0; --j) {
28-
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
28+
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
2929
for (int i = 0; i < image_width; ++i) {
3030
color pixel_color(0,0,0);
3131
for (int s = 0; s < samples_per_pixel; ++s) {
@@ -38,7 +38,7 @@ class scene {
3838
}
3939
}
4040

41-
std::cerr << "\nDone.\n";
41+
std::clog << "\nDone.\n";
4242
}
4343

4444
public:

0 commit comments

Comments
 (0)