9#include <source_location>
27 static inline std::ofstream file_stream;
28 static inline std::mutex file_mutex;
31 static void write(std::string_view message)
35 std::lock_guard<std::mutex> lock(file_mutex);
36 if (!file_stream.is_open())
42 file_stream << message << std::endl;
52 auto now = std::chrono::system_clock::now();
53 auto time = std::chrono::system_clock::to_time_t(now);
54 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
56 std::ostringstream oss;
61 localtime_s(&tm, &time);
63 localtime_r(&time, &tm);
66 oss << std::put_time(&tm,
"%H:%M:%S") <<
'.' << std::setfill(
'0') << std::setw(3) << ms.count();
97 std::string_view funcName)
noexcept
100 const auto& start = std::min(file.find_last_of(
"/"), file.find_last_of(
"\\")) + 1;
101 const auto& substr = file.substr(start, file.size() - start);
111 std::source_location l = std::source_location::current()) noexcept
117#if EASYS_LOG_VERBOSITY
127 constexpr std::uint32_t
line() const noexcept {
return line_; }
134 std::ostringstream oss;
137 <<
"[" << location.
file_name() <<
":" << location.
line() <<
"] "
140 auto final_message = oss.str();
145 std::cerr << final_message << std::endl;
148 std::cout << final_message << std::endl;
167#define EASYS_HERE Easys::log::source_location(__FILE__, __LINE__, __FUNCTION__, __func__)
170#define EASYS_LOG_IMPL(level, msg) \
173 if constexpr (Easys::log::is_enabled<level>::value) \
175 ::Easys::log::log_impl(level, msg, EASYS_HERE); \
180#define EASYS_LOG_ERROR(msg) EASYS_LOG_IMPL(Easys::log::LogLevel::EASYS_ERROR, msg)
181#define EASYS_LOG_INFO(msg) EASYS_LOG_IMPL(Easys::log::LogLevel::EASYS_INFO, msg)
182#define EASYS_LOG_DEBUG(msg) EASYS_LOG_IMPL(Easys::log::LogLevel::EASYS_DEBUG, msg)
183#define EASYS_LOG_TRACE(msg) EASYS_LOG_IMPL(Easys::log::LogLevel::EASYS_TRACE, msg)
184#define EASYS_LOG_ENTRY_EXIT \
187 if constexpr (Easys::log::is_enabled<Easys::log::LogLevel::EASYS_TRACE>::value) \
189 ::Easys::log::EntryExitLogger eel(EASYS_HERE); \
193#define EASYS_E_STR(e) std::format("Entity: {}", e)
194#define EASYS_EC_STR(e) std::format("Entity: {}, Component: {}", e, typeid(T).name())
~EntryExitLogger()
Definition log.hpp:161
EntryExitLogger(Easys::log::source_location location)
Definition log.hpp:156
static void write(std::string_view message)
Definition log.hpp:31
#define EASYS_LOG_FILE_PATH
Defines the file path used for file-based logging.
Definition config.hpp:97
#define EASYS_LOG_ENABLED
Master switch for all logging functionality.
Definition config.hpp:36
#define EASYS_LOG_TO_FILE
Enables or disables logging to a file.
Definition config.hpp:85
#define EASYS_LOG_LEVEL
Sets the global logging level.
Definition config.hpp:72
constexpr std::string_view level_to_string(LogLevel level)
Definition log.hpp:71
LogLevel
Definition log.hpp:17
std::string get_timestamp()
Definition log.hpp:50
void log_impl(LogLevel level, std::string_view message, Easys::log::source_location location)
Definition log.hpp:132
static constexpr bool value
Definition log.hpp:22
constexpr std::string_view file_name() const noexcept
Definition log.hpp:123
std::string_view file_name_
Definition log.hpp:89
std::uint32_t line_
Definition log.hpp:93
constexpr source_location(std::string_view funcName, std::source_location l=std::source_location::current()) noexcept
Definition log.hpp:110
std::string_view function_name_
Definition log.hpp:91
constexpr std::string_view function_name() const noexcept
Definition log.hpp:124
std::string_view function_signature_
Definition log.hpp:92
std::string_view file_path_
Definition log.hpp:90
constexpr source_location(std::string_view file, std::uint32_t line, std::string_view funcSig, std::string_view funcName) noexcept
Definition log.hpp:96
constexpr std::uint32_t line() const noexcept
Definition log.hpp:127