-
Notifications
You must be signed in to change notification settings - Fork 64
Pass log messages from projectM to Poco's logger #132
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,73 @@ | |||||
|
|
||||||
| #include <cmath> | ||||||
|
|
||||||
| #if (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2) | ||||||
| static inline projectm_log_level get_projectM_log_level(Poco::Message::Priority log_level) | ||||||
| { | ||||||
| switch (log_level) | ||||||
| { | ||||||
| case Poco::Message::PRIO_FATAL: | ||||||
| return PROJECTM_LOG_LEVEL_FATAL; | ||||||
| case Poco::Message::PRIO_CRITICAL: | ||||||
| case Poco::Message::PRIO_ERROR: | ||||||
| return PROJECTM_LOG_LEVEL_ERROR; | ||||||
| case Poco::Message::PRIO_WARNING: | ||||||
| return PROJECTM_LOG_LEVEL_WARN; | ||||||
| case Poco::Message::PRIO_NOTICE: | ||||||
| case Poco::Message::PRIO_INFORMATION: | ||||||
| return PROJECTM_LOG_LEVEL_INFO; | ||||||
| case Poco::Message::PRIO_DEBUG: | ||||||
| return PROJECTM_LOG_LEVEL_DEBUG; | ||||||
| case Poco::Message::PRIO_TRACE: | ||||||
| return PROJECTM_LOG_LEVEL_TRACE; | ||||||
| default: | ||||||
| if (log_level >= Poco::Message::PRIO_TRACE) | ||||||
| { | ||||||
| return PROJECTM_LOG_LEVEL_TRACE; | ||||||
| } | ||||||
| return PROJECTM_LOG_LEVEL_NOTSET; | ||||||
| } | ||||||
| return PROJECTM_LOG_LEVEL_NOTSET; | ||||||
| } | ||||||
|
|
||||||
| static inline projectm_log_level get_projectM_log_level(int log_level) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here:
Suggested change
|
||||||
| { | ||||||
| return get_projectM_log_level(static_cast<Poco::Message::Priority>(log_level)); | ||||||
| } | ||||||
|
|
||||||
| static inline Poco::Message::Priority get_poco_log_level(projectm_log_level log_level) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here:
Suggested change
|
||||||
| { | ||||||
| switch (log_level) | ||||||
| { | ||||||
| case PROJECTM_LOG_LEVEL_FATAL: | ||||||
| return Poco::Message::PRIO_FATAL; | ||||||
| case PROJECTM_LOG_LEVEL_ERROR: | ||||||
| return Poco::Message::PRIO_ERROR; | ||||||
| case PROJECTM_LOG_LEVEL_WARN: | ||||||
| return Poco::Message::PRIO_WARNING; | ||||||
| case PROJECTM_LOG_LEVEL_INFO: | ||||||
| return Poco::Message::PRIO_INFORMATION; | ||||||
| case PROJECTM_LOG_LEVEL_DEBUG: | ||||||
| return Poco::Message::PRIO_DEBUG; | ||||||
| case PROJECTM_LOG_LEVEL_TRACE: | ||||||
| return Poco::Message::PRIO_TRACE; | ||||||
| default: | ||||||
| if (log_level >= PROJECTM_LOG_LEVEL_FATAL) | ||||||
| { | ||||||
| return Poco::Message::PRIO_FATAL; | ||||||
| } | ||||||
| return static_cast<Poco::Message::Priority>(0); | ||||||
| } | ||||||
| return static_cast<Poco::Message::Priority>(0); | ||||||
| } | ||||||
|
|
||||||
| static void projectM_log_callback(const char* message, projectm_log_level log_level, void* user_data) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| { | ||||||
| Poco::Logger* logger = static_cast<Poco::Logger*>(user_data); | ||||||
| logger->log(Poco::Message("projectM", message, get_poco_log_level(log_level))); | ||||||
| } | ||||||
| #endif // (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2) | ||||||
|
|
||||||
| const char* ProjectMWrapper::name() const | ||||||
| { | ||||||
| return "ProjectM Wrapper"; | ||||||
|
|
@@ -25,6 +92,11 @@ void ProjectMWrapper::initialize(Poco::Util::Application& app) | |||||
| _userConfig = projectMSDLApp.UserConfiguration(); | ||||||
| poco_information_f1(_logger, "Events enabled: %?d", _projectMConfigView->eventsEnabled()); | ||||||
|
|
||||||
| #if (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2) | ||||||
| projectm_set_log_level(get_projectM_log_level(_PMlogger.getLevel()), false); | ||||||
| projectm_set_log_callback(projectM_log_callback, false, &_PMlogger); | ||||||
| #endif | ||||||
|
|
||||||
| if (!_projectM) | ||||||
| { | ||||||
| auto& sdlWindow = app.getSubsystem<SDLRenderingWindow>(); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -113,5 +113,8 @@ class ProjectMWrapper : public Poco::Util::Subsystem | |||||
|
|
||||||
| Poco::NObserver<ProjectMWrapper, PlaybackControlNotification> _playbackControlNotificationObserver{*this, &ProjectMWrapper::PlaybackControlNotificationHandler}; | ||||||
|
|
||||||
| Poco::Logger& _logger{Poco::Logger::get("SDLRenderingWindow")}; //!< The class logger. | ||||||
| Poco::Logger& _logger{Poco::Logger::get("ProjectMWrapper")}; //!< The class logger. | ||||||
| #if (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2) | ||||||
| Poco::Logger& _PMlogger{Poco::Logger::get("ProjectM")}; //!< The logger for projectM. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be keeping the proper member name casing here, also there's no need to abbreviate the name:
Suggested change
|
||||||
| #endif | ||||||
| }; | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Pascal case for function and class names and lower Pascal case for variables/arguments to keep things aligned with the existing style:
(Lower snake case is used primarily in C code, which is why the projectM API uses it)