For an older Fortran project, I tried to create a modern logger. It was written object-oriented very similar to python's logging library.
The last thing that bothers me is formating, I will explain.
My logger looks very similar to this library, however, it did not meet my requirements so I wrote my own. Basically my logging library looks something like this:
lg = Logger("super logger")
... other settings ...
lg%log("DEBUG", "A cool message to log", rank)
but with this logger, I lost all of the formatting capabilities of the write statement. Basically in the code string formatting is done by write statements such as:
write (stdout, '(7X,A,f12.6)') "The great number is ", number
So now I have to have two lines of code for every output statement and auxiliary variable:
write (message, '(A,f12.6)') "The great number is ", number
lg%log("DEBUG", message, rank)
which is not very convenient nor nice.
I was trying to do a formatting function, but I guess it is not possible with a variable number of arguments (like in C) e.g:
function fm(fmt, ...) result(message)
I believe I cannot do a C workaround either because when I specify the binding interface I have to specify arguments.
The only solution I have now (except the two-line example) is to overload some method for different variables and create something like streams in c++.
my question is do you have a better idea? Ideally, if you know about a option how to format string in one line.