Pass log messages from projectM to Poco's logger - #132
Conversation
kblaschke
left a comment
There was a problem hiding this comment.
While this is certainly a great addition, this code won't compile/link with all libprojectM versions, as the logging API is a new feature in the unreleased 4.2 version.
At the very least, the projectM version should be checked at compile time and then enable certain features according to the libprojectM API version the app is being built against. This is to make sure the application can be built & used on as many platforms as possible, including those not shipping the latest libprojectM (LTS distros for example won't update libraries to higher versions, only releasing bug and security fixes).
There are different ways of implementing such a check, all of which will include wrapping code into #ifdef/#if macros:
- Comparing the projectM major/minor version in
#if (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2)preprocessor directives - Let CMake check for each function to be available using the
CheckFunctionExistsmodule and including the projectM header. - Determine the projectM version in CMake (via the
projectM4_VERSIONCMake variable defined by the package) and set compiler defines for each minor version available in the one used for building.
I don't think the built app should be backwards-compatible at runtime (e.g. replacing the projectM shared library from the build with an older one), as this would imply lots of additional work in the code and runtime checks for available functions. This won't be a use case, and thus only forward compatibility is needed.
9d07034 to
5fdddea
Compare
|
I went with |
kblaschke
left a comment
There was a problem hiding this comment.
With the naming changes applied, it's good for merging.
Optionally, you could also use explicit operator= overrides instead of these functions to automatically convert the values on assignment/use, which makes the calls look a bit cleaner.
| 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. |
There was a problem hiding this comment.
Should be keeping the proper member name casing here, also there's no need to abbreviate the name:
| Poco::Logger& _PMlogger{Poco::Logger::get("ProjectM")}; //!< The logger for projectM. | |
| Poco::Logger& _projectMLogger{Poco::Logger::get("ProjectM")}; //!< The logger for projectM. |
| #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) |
There was a problem hiding this comment.
Please use Pascal case for function and class names and lower Pascal case for variables/arguments to keep things aligned with the existing style:
| static inline projectm_log_level get_projectM_log_level(Poco::Message::Priority log_level) | |
| static inline projectm_log_level GetProjectMLogLevel(Poco::Message::Priority logLevel) |
(Lower snake case is used primarily in C code, which is why the projectM API uses it)
| return PROJECTM_LOG_LEVEL_NOTSET; | ||
| } | ||
|
|
||
| static inline projectm_log_level get_projectM_log_level(int log_level) |
There was a problem hiding this comment.
Same here:
| static inline projectm_log_level get_projectM_log_level(int log_level) | |
| static inline projectm_log_level GetProjectMLogLevel(int logLevel) |
| 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) |
There was a problem hiding this comment.
And here:
| static inline Poco::Message::Priority get_poco_log_level(projectm_log_level log_level) | |
| static inline Poco::Message::Priority GetPocoLogLevel(projectm_log_level logLevel) |
| return static_cast<Poco::Message::Priority>(0); | ||
| } | ||
|
|
||
| static void projectM_log_callback(const char* message, projectm_log_level log_level, void* user_data) |
There was a problem hiding this comment.
| static void projectM_log_callback(const char* message, projectm_log_level log_level, void* user_data) | |
| static void ProjectMLogCallback(const char* message, projectm_log_level logLevel, void* userData) |
Good idea. I'll try that when I get around to updating the PR with the rest of your requested changes. |
No description provided.