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

Add built-in logging support and other fixes #566

Merged
merged 8 commits into from
Dec 4, 2024

Conversation

mkilgore
Copy link
Contributor

This is getting close to being ready so I wanted to get some eyes on it:

This adds new logging capabilities to QB64, both internally from libqb and also exposed to the QB64 code. Beyond being a bit nicer than Prints since it captures the function name and line number, a big feature is that logging an error captures a stacktrace of the program at that point. Logging can also easily be turned on without recompilation via environment variables, and can be filtered via various scopes and a couple different logging levels. Overall this should hopefully be a big aid for debugging, as we can ask users to provide us with the logging output of programs when they error.

Below is an example of some logging from a QB64 program (note how the IDE opens a separate console window to display it):
image

The new commands are _LogTrace, _LogInfo, _LogWarn, _LogError, _LogMinLevel. The first four write out log messages at the indicated log level. The last returns a number indicating the lowest level of logging is enabled, allowing you to skip generating more expensive logging if it won't be displayed.

Logging is enabled via a variety of different environment variables (when run from the IDE these are configured automatically):

  1. QB64PE_LOG_LEVEL - sets the lowest log level to display, options are Trace, Information, Warning, Error
  2. QB64PE_LOG_SCOPES - A comma-separated list of different sets of logging to turn on, allowing basic filtering of what is displayed. Options are:
    a. libqb - Some generic logging from libqb, such as error codes when they happen, program startup/shutdown, etc.
    b. libqb-image - Logging from the image subsystem (when images are loaded,freed, errors that happen, etc.)
    c. libqb-audio - Logging from the audio subsystem
    d. qb64 - Logging from the QB64 Program ( _Log* statements)
  3. QB64PE_LOG_HANDLERS - A comma-separated list of the logging handlers to enable. If no handlers are enabled, then no logging is generated. Current options are:
    a. console - Logging output is written to the console.
    b. file - Writes logs to the file set via the QB64PE_LOG_FILE_PATH environment variable

Currently the IDE just defaults to using Information and enabling all the scopes, in a future update I'd like to have an IDE dialog that lets you pick the log level and scopes.

@mkilgore mkilgore force-pushed the logging-changes-2 branch 2 times, most recently from 251dcbc to ee1e23e Compare November 22, 2024 06:57
@mkilgore mkilgore changed the title [WIP] Add built-in logging support and other fixes Add built-in logging support and other fixes Nov 22, 2024
@mkilgore
Copy link
Contributor Author

This is ready to be reviewed, there's a couple other things to do (IDE dialog for configuring logging, convert the audio logging, coloring the output, etc.) but those can be left for separate PRs.

This change allows QB64 programs to send stdout output to their parent
console if started from one. This works regardless of `$CONSOLE` usage,
which is useful for `_Echo` and `_Log*` statements which can always go
to console regardless of `$CONSOLE` settings.

We also allow a msys or cygwin pipe to be used in place of a proper
console, as that's good enough for our basic output from `_Echo` and
`_Log*` statements (and more convient than starting a separate console
window). If we're an actual `$CONSOLE` program than a separate console
will always be started.
On Windows, if the time goes backwards (IE. someone sets the system date
to an earlier time) then `clock()` starts returning large negative
values.

To avoid this we're switching GetTicks to use a different Windows API to
track the time since the start of the program.
This allows the user to enable logging from within the IDE. When they do
this, environment variables will be set to turn on logging to console
at Information level with a default set of logging scopes. The program
is started with a separate console to allow the logging to be viewed
separate from the program (unless the program is $Console:Only and has
no graphical view).

The terminal configuration is specific for Linux and used for both
logging output and $Console programs. It allows the user to configure a
terminal emulator to be used for running programs, allowing the output
of $Console programs to be viewed from it as well as logging output when
enabled.

When no terminal is configured we have logic that checks a list of
common terminal emulators to see if any of them are availiable, and if
so uses a known good configuration for them. The user can change
this via a GUI dialog.
@mkilgore mkilgore merged commit ff510e1 into QB64-Phoenix-Edition:main Dec 4, 2024
4 checks passed
@RhoSigma-QB64 RhoSigma-QB64 mentioned this pull request Dec 4, 2024
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.

3 participants