-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #60 Added logging utility function to be able to see logs while …
…reunning unit tests.
- Loading branch information
Florent Peyrusse
committed
Jul 13, 2023
1 parent
6f924ea
commit ce42f26
Showing
6 changed files
with
146 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Fledge HNZ south plugin. | ||
* | ||
* Copyright (c) 2022, RTE (https://www.rte-france.com) | ||
* | ||
* Released under the Apache 2.0 Licence | ||
* | ||
* Author: Justin Facquet | ||
* | ||
*/ | ||
|
||
#ifndef _HNZ_UTILITY_H | ||
#define _HNZ_UTILITY_H | ||
|
||
#include <string> | ||
#include <logger.h> | ||
|
||
namespace HnzUtility { | ||
/* | ||
* Log helper function that will log both in the Fledge syslog file and in stdout for unit tests | ||
*/ | ||
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)...); | ||
} | ||
|
||
template<class... Args> | ||
void log_info(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()->info(format.c_str(), std::forward<Args>(args)...); | ||
} | ||
|
||
template<class... Args> | ||
void log_warn(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()->warn(format.c_str(), std::forward<Args>(args)...); | ||
} | ||
|
||
template<class... Args> | ||
void log_error(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()->error(format.c_str(), std::forward<Args>(args)...); | ||
} | ||
|
||
template<class... Args> | ||
void log_fatal(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()->fatal(format.c_str(), std::forward<Args>(args)...); | ||
} | ||
} | ||
|
||
#endif /* _HNZ_UTILITY_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.