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

Allow redirection of lcf console messages #416

Merged
merged 5 commits into from
Mar 28, 2024
Merged

Conversation

Ghabry
Copy link
Member

@Ghabry Ghabry commented Mar 15, 2021

First commit: The chunk dumping during Skip didnt really work except on Windows. I finally fixed it (useful for Maniacs Patch to find unknown chunks). Also is now always on, a missing chunk is now always a bug because we know about all common ones.

Second commit: I want your feedback here. Before I implement this completely (is some work) please tell me if the general approach is fine for you.
I want to allow custom output handlers for lcf diagnostics. E.g. for the Player they could be written to easyrpg_log.txt. Currently they are completely lost which is bad for handling bug reports. As vital information is missing.

To redirect it library users can invoke lcf::LogHandler::SetHandler(Handlerfunctionhere)

@Ghabry Ghabry added the RFC label Mar 15, 2021
@fdelapena
Copy link
Contributor

fdelapena commented Mar 16, 2021

There's a good chance to add more levels, such trace, info, notice, while critical, alert, emergency feel a bit unneeded.
At least those for matching not just with Player, but cover at least the levels existing in JavaScript's console.xxx() (debug, log [which level to use here? default to unclassified stdout?], info, warn and error). Emscripten shell currently uses console.error() for everything but this is easy to fix and helps a lot to filter details from the browser developer tools.

Update: severity levels exists in Player already, so matching with them makes sense nowadays.

@aleck099
Copy link

aleck099 commented Feb 14, 2022

Why are exceptions disabled in liblcf?

@Ghabry
Copy link
Member Author

Ghabry commented Feb 14, 2022

Same reason why we disable RTTI:

Portability. We have some quite low spec homebrew platforms that we support.
They are low on memory and load the executable into memory so every kilobyte counts.
Also exceptions are also not well supported in emscripten.

We also do not want to maintain two codepaths. So no exception it is.

@aleck099
Copy link

But is printing to stderr a good choice?

@Ghabry
Copy link
Member Author

Ghabry commented Feb 14, 2022

Uhm no that is why I plan to make this configurable in this PR?

Currently errors land on stderr.
With this PR consumers of this library (e.g. the Player) can hook it into their logging system (which logs into easyrpg_log.txt)

@aleck099
Copy link

Looking forward to begin merged

@fdelapena fdelapena requested a review from carstene1ns June 22, 2022 16:15
@Ghabry Ghabry added this to the 0.8.0 milestone Apr 16, 2023
@Ghabry Ghabry changed the title RFC/WIP: Allow redirection of lcf console messages Allow redirection of lcf console messages Apr 25, 2023
@Ghabry Ghabry removed this from the 0.8.0 milestone Apr 25, 2023
@Ghabry
Copy link
Member Author

Ghabry commented Apr 25, 2023

I rechecked the code now: There is literally nothing finished here yet. Except for one example usage. Can't finish this for 0.8.0 in such short time.

Hot candidate for 0.8.1

@Ghabry Ghabry added this to the 0.8.1 milestone Apr 25, 2023
For XML the SetError function was removed and is printed directly.

Tracing stuff (LCF_DEBUG_TRACE) goes now through fprintf.
Not worth to send this through the logger as is off by default.
@carstene1ns
Copy link
Member

I think on liblcf side is not much missing anymore. The handler function concept is well-known and works. Usually you get some void *userdata context to pass, which we maybe should make available for custom loggers.

@Ghabry Ghabry marked this pull request as ready for review December 5, 2023 22:08
@Ghabry
Copy link
Member Author

Ghabry commented Dec 5, 2023

Suitable logging function for use in Player:

lcf::LogHandler::SetHandler([](lcf::LogHandler::Level level, StringView message, lcf::LogHandler::UserData) {
    Output::Debug("lcf ({}): {}", lcf::LogHandler::kLevelTags.tag(level), message);
});

So currently only written to terminal/logfile.

Not sure if any of the stuff should be reported through the graphical "console" inside the window. Most of that stuff is recoverable (similar to the libpng warnings spamming the shell) and everything critical is already shown as an "Output::Error".

Copy link
Member

@carstene1ns carstene1ns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it a bit messy that at first every log message is made a C-String, then a C++ std::string and last a string_view.
Maybe we should make fmt a lcf dependency in the future to hide the conversions.

Apart from the minor nits, LGTM

src/lcf/log_handler.h Outdated Show resolved Hide resolved
src/log.h Show resolved Hide resolved
src/log.h Show resolved Hide resolved
@carstene1ns carstene1ns merged commit ad97cac into EasyRPG:master Mar 28, 2024
10 checks passed
if ((i+1) % 16 == 0) {
fprintf(stderr, "\n");
Log::Debug(ss.str().c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android (clang) build fails with -Wformat-security:

Log::Debug("%s", ss.str().c_str());

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

Successfully merging this pull request may close these issues.

4 participants