Open ian-m-carr opened 1 year ago
Thanks for the contribution! Can I ask you to make a couple of changes, please? First, if you look in l_my_print(), there's a standard prefix that's used for the log to give a timestamp and a feature code. That should be added to the start of any other lines directed towards XPLMDebugString().
Second, there are people who will still expect printf output so instead of using an #ifdef to choose one behaviour or the other, just have your new log function also output to console, again as l_my_print() does.
If you can merge the two functions - your new log_message and the lua-side l_my_print - so much the better.
I'll take a look!
Do you want me to reverse the #if def to allow the new log messages to be compiled out, or just keep both in?
I think remove the #ifdefs. If the new log function sends to both the log and console there's no need to be able to separate them at compile time.
OK, the prefix requires access to the dataref, currently static inside xpfuncs. Would you prefer: 1) I keep the logging in a separate cpp file and duplicate the dataref, (logging is a rare occurrence, and initialization on first call is possible) 2) provide an accessor to the existing dataref in xpfuncs, 3) or move the logging implementation into xpfuncs?
Option 3 seems cleanest.
Think that's what you asked for!
Hold off missing braces!
The Warning if required additional braces now it has two logging lines! This now runs as before on my aircraft, with the new prefix and time-codes.
On Windows, the current xlua messages sent to the stdout of the process come from a process other than the one launched, so redirecting to a file does not capture them. Without them syntax and other errors are far harder to catch!
This change replaces the 'printf's with a function which uses XPLMDebugString to direct the otherwise missing content to the X-Plane logfile.
In addition the traceback function now triggers a log message so again it is visible on Windows.
This change can be compiled out by #defining NO_LOG_MESSAGE