tinyrpc/includes/log/logger.hpp

41 lines
660 B
C++
Raw Normal View History

#pragma once
#include <iostream>
#include <ostream>
// #define LOGGER (std::cout << __FILE__ << ":" << __LINE__)
2025-02-07 15:35:03 +08:00
struct Logger {
Logger() = default;
2025-02-07 15:35:03 +08:00
template <typename T>
std::ostream& operator<<(T&& msg)
{
2024-12-17 15:47:10 +08:00
return std::cout << msg;
}
2025-02-07 15:35:03 +08:00
~Logger()
{
std::cout << std::endl;
}
2025-02-07 15:35:03 +08:00
2024-12-17 15:47:10 +08:00
};
2025-02-07 15:35:03 +08:00
struct IgnoreLogger {
IgnoreLogger() = default;
template <typename T>
IgnoreLogger& operator<<(T&& msg)
{
return *this;
}
~IgnoreLogger() = default;
};
#define logger() (Logger() << __FILE__ << ":" << __LINE__ << " ")
// #define logger1() (Logger() << __FILE__ << ":" << __LINE__ << " ")