Skip to content

Allow redirection of lcf console messages#416

Merged
carstene1ns merged 5 commits into
EasyRPG:masterfrom
Ghabry:output
Mar 28, 2024
Merged

Allow redirection of lcf console messages#416
carstene1ns merged 5 commits into
EasyRPG:masterfrom
Ghabry:output

Conversation

@Ghabry

@Ghabry Ghabry commented Mar 15, 2021

Copy link
Copy Markdown
Member

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
@ghost

ghost commented Mar 16, 2021

Copy link
Copy Markdown

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

aleck099 commented Feb 14, 2022

Copy link
Copy Markdown

Why are exceptions disabled in liblcf?

@Ghabry

Ghabry commented Feb 14, 2022

Copy link
Copy Markdown
Member Author

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
Copy Markdown

But is printing to stderr a good choice?

@Ghabry

Ghabry commented Feb 14, 2022

Copy link
Copy Markdown
Member Author

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
Copy Markdown

Looking forward to begin merged

@ghost ghost added the Needs Rebase label Feb 15, 2022
@ghost ghost 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

Ghabry commented Apr 25, 2023

Copy link
Copy Markdown
Member Author

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.
@ghost ghost added the Enhancement label Dec 1, 2023
@ghost ghost removed the Needs Rebase label Dec 5, 2023
@carstene1ns

Copy link
Copy Markdown
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

Ghabry commented Dec 5, 2023

Copy link
Copy Markdown
Member Author

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".

@carstene1ns carstene1ns left a comment

Copy link
Copy Markdown
Member

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

Comment thread src/lcf/log_handler.h Outdated
Comment thread src/log.h
Comment thread src/log.h
@carstene1ns carstene1ns merged commit ad97cac into EasyRPG:master Mar 28, 2024
Comment thread src/reader_lcf.cpp
ss << std::setfill('0') << std::setw(2) << (int)byte << " ";
if ((i+1) % 16 == 0) {
fprintf(stderr, "\n");
Log::Debug(ss.str().c_str());

Copy link
Copy Markdown
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.

3 participants