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 redefinition of where logging goes #111

Merged
merged 5 commits into from
Jul 6, 2024

Conversation

thirstyice
Copy link
Contributor

Sometimes I want to log to places other than Serial (when I have a display connected, or when my adapter is attached to Serial1 for example)

Also adds guards so things don't break when the user disables Serial

Copy link
Owner

@hideakitai hideakitai left a comment

Choose a reason for hiding this comment

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

Thank you, please check the comments.

protected:
void attach(S& s)
{
this->stream = &s;
}

#if defined(NO_GLOBAL_INSTANCES) || defined(NO_GLOBAL_SERIAL)
Copy link
Owner

Choose a reason for hiding this comment

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

Could you let me know what these preprocessors are?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're the same macros that allow disabling Serialet al in the esp32 arduino core (see here).
I had assumed when I was developing this that they were standard across all arduino cores, but it seems that they are not.

protected:
void attach(S& s)
{
this->stream = &s;
}

#if defined(NO_GLOBAL_INSTANCES) || defined(NO_GLOBAL_SERIAL)
Print* log = nullptr; // No Serial -> no output
Copy link
Owner

Choose a reason for hiding this comment

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

I think if the user doesn’t set this, the program crashes. (nullptr->print() will be called)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upon further research: this is actually undefined behaviour (not neccesarily a crash), which is why I didn't catch it earlier.
Solution coming soon.

With logging disabled by default via the log variable it's somewhat redundant
@thirstyice
Copy link
Contributor Author

Added a subclass of Print that does nothing, which is now the default log output. The user can then choose if + where to log by calling logOutputTo.

Removed b_verbose, as it seemed redundant to have to call 2 separate functions to enable logging.

This way we also don't have to worry about what happens if Serial is undefined, that becomes the user's problem.

Copy link
Owner

@hideakitai hideakitai left a comment

Choose a reason for hiding this comment

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

Almost LGTM. Please check the comment

Artnet/Common.h Outdated Show resolved Hide resolved
Artnet/Receiver.h Outdated Show resolved Hide resolved
Artnet/Receiver.h Outdated Show resolved Hide resolved
@hideakitai hideakitai merged commit ea329ab into hideakitai:main Jul 6, 2024
33 checks passed
@thirstyice thirstyice deleted the redefSerial branch July 6, 2024 19:08
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