sh3redux icon indicating copy to clipboard operation
sh3redux copied to clipboard

Consider libfmt for Log

Open z33ky opened this issue 6 years ago • 5 comments

Consider using fmt for Log().

z33ky avatar Jan 23 '18 18:01 z33ky

hmm looks really good. What sort of improvements would this have over what we've currently got though? For the most part, Log() does what we need it to (print to stderr and Log.txt). Some kind of safety? (from what I can read)

Quaker762 avatar Jan 24 '18 10:01 Quaker762

"Support for user-defined types" is the major motivator for me. Being able to just Log(LogLevel::WARN, "{} does not align with {}\n", vecA, vecB) instead of Log(LogLevel::WARN, "%f %f %f does not align with %f %f %f\n", vecA.x, vecA.y, vecA.z, vecB.x, vecB.y, vecB.z) is a big improvement. Of course we could also use macros to trim it down some:

#define VEC_FMT "%f %f %f"
//FIXME: if vec is evaluated multiple times
#define VEC_FMT_ARG(vec) (vec).x, (vec).y, (vec).z
...
Log(LogLevel::WARN, VEC_FMT " does not align with " VEC_FMT, VEC_FMT_ARG(vecA), VEC_FMT_ARG(vecB));

Neither works well if we want to customize vector printing though, e.g. if we just want to print two decimal places. In either case we can still fall back to vecA.x, vecA.y, vecA.z. We could perhaps look if we can extent fmt for that usecase though. With just printf we could implement parsing of the format string ourselves, which is not terribly defficult, but I think still wasted effort.

z33ky avatar Jan 24 '18 10:01 z33ky

Err okay, that last thing is already possible in fmt: http://fmtlib.net/latest/api.html#formatting-user-defined-types

Edit: link correct section

z33ky avatar Jan 24 '18 10:01 z33ky

Did you still want to use this? I just had another look and it'll definitely make our lives a whole lot easier.

I'll leave it up to you though, it'll be a disaster if I do it hahaha.

Quaker762 avatar Feb 19 '18 15:02 Quaker762

Yes, I still believe this is a good option for us.

z33ky avatar Feb 21 '18 11:02 z33ky