sail-riscv icon indicating copy to clipboard operation
sail-riscv copied to clipboard

Don't use `fprintf` for printing

Open Arielfoever opened this issue 3 months ago • 7 comments

People generate logs via fprintf is really ugly and diffcult to manage.

Arielfoever avatar Aug 13 '25 07:08 Arielfoever

Yeah I also don't like fprintf. We could use iostreams but they also kind of suck. std::print is much nicer but only available in C++23. Maybe we just wait a few years...

Timmmm avatar Aug 13 '25 07:08 Timmmm

Maybe things like spdlog

trdthg avatar Aug 13 '25 09:08 trdthg

I've used spdlog in the past. It's pretty good but has compilation time issues.

For the actual formatting it uses fmt which is basically what C++20/23 copied for std::format. I wonder if anyone has made some kind of polyfill for the actual std::format/print. That would probably be ideal.

Timmmm avatar Aug 13 '25 11:08 Timmmm

How about libfmt, although it would add additional library dependency

KotorinMinami avatar Aug 30 '25 15:08 KotorinMinami

Why is fprintf such a problem in a way that C++ equivalents aren’t? This feels like change for change’s sake.

jrtc27 avatar Aug 30 '25 16:08 jrtc27

It's not a big problem really. std::print/fmt::print is just a bit easier to use and more difficult to get wrong.

I would say it's fine to leave it for now and wait until C++23 is acceptable (2028?). But if someone really wants to add fmt I won't stop them...

Timmmm avatar Aug 30 '25 20:08 Timmmm

I see something like zlog - you can edit your output format in config.

Arielfoever avatar Nov 01 '25 14:11 Arielfoever