To save time when debugging with Print statements, I'd like to define a function -- call it PrintVal -- that prints both the name and value of a variable defined locally within the calling function. The function would be called with a single argument, which would be the name of the variable in question (expressed in the form of a string). To provide a concrete example, if fooVar is a variable defined as local to a module within the calling function, and if the current value of fooVar is 9, then
PrintVal[ "fooVar" ]
should print
fooVar = 9
The new function would thus have the same effect as including the statement
Print[ "fooVar = ", fooVar ]
directly within the calling function itself, but without the need to type the variable name twice, to include the equal sign, and (most important from a time-saving perspective) to include some other formatting stuff that I haven't mentioned here (because it's not relevant to the part I'm struggling with).
Although there may well be an embarrassingly simple solution that I don't know enough to have thought of, after a considerable amount of experimentation, documentation-reading, and web-searching, I've been unable to find one. With apologies in advance if I'm missing something obvious, I'd be very grateful to anyone who might provide a (detailed and concrete) solution.
Many thanks!
PrintVal[fooVar]
instead if the output were the same? $\endgroup$