Skip to content

Log xlua failures messages to the X-Plane log file. - #15

Open
ian-m-carr wants to merge 4 commits into
X-Plane:masterfrom
ian-m-carr:feat-fails-to-log
Open

Log xlua failures messages to the X-Plane log file.#15
ian-m-carr wants to merge 4 commits into
X-Plane:masterfrom
ian-m-carr:feat-fails-to-log

Conversation

@ian-m-carr

Copy link
Copy Markdown

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

@jimkeir-laminar

Copy link
Copy Markdown
Collaborator

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.

@ian-m-carr

Copy link
Copy Markdown
Author

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?

@jimkeir-laminar

Copy link
Copy Markdown
Collaborator

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.

@ian-m-carr

Copy link
Copy Markdown
Author

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?

@jimkeir-laminar

Copy link
Copy Markdown
Collaborator

Option 3 seems cleanest.

log_message implementation moved to xpfuncs.cpp
#if defines for log/print alternative removed now always performs both
@ian-m-carr

Copy link
Copy Markdown
Author

Think that's what you asked for!

@ian-m-carr

Copy link
Copy Markdown
Author

Hold off missing braces!

@ian-m-carr

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants