Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ian-m-carr
Copy link

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
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
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
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
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
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
Author

Think that's what you asked for!

@ian-m-carr
Copy link
Author

Hold off missing braces!

@ian-m-carr
Copy link
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