Skip to content

Pass log messages from projectM to Poco's logger - #132

Open
SwooshyCueb wants to merge 2 commits into
projectM-visualizer:masterfrom
SwooshyCueb:projectm-logging
Open

Pass log messages from projectM to Poco's logger#132
SwooshyCueb wants to merge 2 commits into
projectM-visualizer:masterfrom
SwooshyCueb:projectm-logging

Conversation

@SwooshyCueb

Copy link
Copy Markdown

No description provided.

@kblaschke kblaschke 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.

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 CheckFunctionExists module and including the projectM header.
  • Determine the projectM version in CMake (via the projectM4_VERSION CMake 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.

@SwooshyCueb

Copy link
Copy Markdown
Author

I went with #if (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2), seemed the simplest approach

@kblaschke kblaschke 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.

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.

Comment thread src/ProjectMWrapper.h
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.

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.

Should be keeping the proper member name casing here, also there's no need to abbreviate the name:

Suggested change
Poco::Logger& _PMlogger{Poco::Logger::get("ProjectM")}; //!< The logger for projectM.
Poco::Logger& _projectMLogger{Poco::Logger::get("ProjectM")}; //!< The logger for projectM.

Comment thread src/ProjectMWrapper.cpp
#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)

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.

Please use Pascal case for function and class names and lower Pascal case for variables/arguments to keep things aligned with the existing style:

Suggested change
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)

Comment thread src/ProjectMWrapper.cpp
return PROJECTM_LOG_LEVEL_NOTSET;
}

static inline projectm_log_level get_projectM_log_level(int log_level)

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.

Same here:

Suggested change
static inline projectm_log_level get_projectM_log_level(int log_level)
static inline projectm_log_level GetProjectMLogLevel(int logLevel)

Comment thread src/ProjectMWrapper.cpp
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)

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.

And here:

Suggested change
static inline Poco::Message::Priority get_poco_log_level(projectm_log_level log_level)
static inline Poco::Message::Priority GetPocoLogLevel(projectm_log_level logLevel)

Comment thread src/ProjectMWrapper.cpp
return static_cast<Poco::Message::Priority>(0);
}

static void projectM_log_callback(const char* message, projectm_log_level log_level, void* user_data)

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.

Suggested change
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)

@SwooshyCueb

Copy link
Copy Markdown
Author

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.

Good idea. I'll try that when I get around to updating the PR with the rest of your requested changes.

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