From 7e743b73433475df086fcec81be7b10c1d695a42 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Fri, 7 May 2021 02:18:07 +0300 Subject: initial --- src/logging.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/logging.h (limited to 'src/logging.h') diff --git a/src/logging.h b/src/logging.h new file mode 100644 index 0000000..2e84198 --- /dev/null +++ b/src/logging.h @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#ifndef INVERTER_TOOLS_LOGGING_H +#define INVERTER_TOOLS_LOGGING_H + +#include +#include +#include + +class custom_log +{ +private: + std::ostream& os_; + +public: + custom_log(std::ostream& os, const std::string& func) : os_(os) { + os_ << func << ": "; + } + + template + custom_log &operator<<(const T &v) { + os_ << v; + return *this; + } + + ~custom_log() { + os_ << std::endl; + } +}; + +inline std::string method_name(const std::string& function, const std::string& pretty) { + size_t locFunName = pretty.find(function); + size_t begin = pretty.rfind(" ", locFunName) + 1; + size_t end = pretty.find("(", locFunName + function.length()); + return pretty.substr(begin, end - begin) + "()"; + } + +#define __METHOD_NAME__ method_name(__FUNCTION__, __PRETTY_FUNCTION__) + +#define mylog custom_log(std::cout, __METHOD_NAME__) +#define myerr custom_log(std::cerr, __METHOD_NAME__) + +#endif //INVERTER_TOOLS_LOGGING_H -- cgit v1.2.3