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

Display all Fledge logs in stdout during unit tests #1207

Open
FlorentP42 opened this issue Oct 20, 2023 · 0 comments · May be fixed by #1208
Open

Display all Fledge logs in stdout during unit tests #1207

FlorentP42 opened this issue Oct 20, 2023 · 0 comments · May be fixed by #1208
Assignees

Comments

@FlorentP42
Copy link
Contributor

FlorentP42 commented Oct 20, 2023

Is your feature request related to a problem? Please describe.
Right now the Logger class only logs into specific Fledge output files and not into the standard output, meaning they will not appear when running unit tests.
Having a compile time flag to make all Fledge logs appear in stdout while running unit tests would be quite useful in plugin debugging phase.

Describe the solution you'd like
A solution would be to provide log function wrappers that would call both the Logger and the printf() function when a compile time flag is on so that the log is visible in both places.
Example of wrapper function for one log level:

namespace LogUtils {
    template<class... Args>
    void log_debug(const std::string& format, Args&&... args) {  
        #ifdef UNIT_TEST
        printf(std::string(format).append("\n").c_str(), std::forward<Args>(args)...);
        fflush(stdout);
        #endif
        Logger::getLogger()->debug(format.c_str(), std::forward<Args>(args)...);
    }
}

Example of precompiler definition to add to the tests CMakeLists:

target_compile_definitions(${PROJECT_NAME} PRIVATE UNIT_TEST)

Example of usage:

LogUtils::log_debug("Logging some debug data: %s", data.c_str());

Describe alternatives you've considered
A more advanced approach would be to further upgrade the Logger class into handling multiple types of appenders so that the user could define its own appenders when configuring Fledge (see examples of implementation in https://log4cpp.sourceforge.net/).
This was not retained so far as it would have more impact on existing code and may result in interface evolutions.

Additional context
N/A

FlorentP42 pushed a commit to FlorentP42/fledge that referenced this issue Oct 20, 2023
FlorentP42 pushed a commit to FlorentP42/fledge that referenced this issue Oct 20, 2023
…gs in unit tests output.

Signed-off-by: Florent Peyrusse <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants