Mana
Log.h
Go to the documentation of this file.
1 
8 /*
9 Do not use the macros in this file,
10 as the handling of strings within mana has not been finalized.
11 */
12 
13 #pragma once
14 #include "common/Platform.h"
15 #include <string>
16 #include <string_view>
17 
18 #if defined(UE_BUILD)
19 // Unreal Engine environment (applies to Shipping/Development/Debug)
20 #define MANA_CHAR TCHAR
21 #define MANA_TEXT(text) TEXT(text)
22 
23 #elif defined(_WIN32) || defined(_WIN64)
24 // Non‑UE Windows environment
25 #define NOMINMAX
26 #include <stdio.h>
27 #include <tchar.h>
28 #define MANA_CHAR TCHAR
29 #define MANA_TEXT(text) _T(text)
30 
31 #else
32 // Non‑UE, non‑Windows environment
33 #include <iostream>
34 #define MANA_CHAR char
35 #define MANA_TEXT(text) (text)
36 #endif
37 
38 namespace mana
39 {
40  [[nodiscard]] inline std::basic_string<MANA_CHAR> LogConcat(std::initializer_list<std::basic_string_view<MANA_CHAR>> r)
41  {
42  std::size_t n = 0;
43  for (auto s : r)
44  n += s.size();
45  std::basic_string<MANA_CHAR> l;
46  l.reserve(n);
47  for (auto s : r)
48  l.append(s);
49  return l;
50  }
51 }
52 
53 #if defined(UE_BUILD)
54  // Unreal Engine environment (applies to Shipping/Development/Debug)
55  #define MANA_LOG_ERROR(...) UE_LOG(LogTemp, Error, MANA_TEXT("%s\n"), mana::LogConcat({ __VA_ARGS__ }).c_str())
56  #define MANA_LOG_WARNING(...) UE_LOG(LogTemp, Warning, MANA_TEXT("%s\n"), mana::LogConcat({ __VA_ARGS__ }).c_str())
57  #define MANA_LOG_DISPLAY(...) UE_LOG(LogTemp, Display, MANA_TEXT("%s\n"), mana::LogConcat({ __VA_ARGS__ }).c_str())
58  #define MANA_LOG_INFO(...) UE_LOG(LogTemp, Log, MANA_TEXT("%s\n"), mana::LogConcat({ __VA_ARGS__ }).c_str())
59 
60 #elif defined(_WIN32) || defined(_WIN64)
61  // Non‑UE Windows environment
62  #define MANA_LOG_ERROR(...) _tprintf(MANA_TEXT("%s\n"), mana::LogConcat({ __VA_ARGS__ }))
63  #define MANA_LOG_WARNING(...) _tprintf(MANA_TEXT("%s\n"), mana::LogConcat({ __VA_ARGS__ }))
64  #define MANA_LOG_DISPLAY(...) _tprintf(MANA_TEXT("%s\n"), mana::LogConcat({ __VA_ARGS__ }))
65  #define MANA_LOG_INFO(...) _tprintf(MANA_TEXT("%s\n"), mana::LogConcat({ __VA_ARGS__ }))
66 
67 #else
68  // Non‑UE, non‑Windows environment
69  #define MANA_LOG_ERROR(...) (std::cout << mana::LogConcat({ __VA_ARGS__ }) << '\n')
70  #define MANA_LOG_WARNING(...) (std::cout << mana::LogConcat({ __VA_ARGS__ }) << '\n')
71  #define MANA_LOG_DISPLAY(...) (std::cout << mana::LogConcat({ __VA_ARGS__ }) << '\n')
72  #define MANA_LOG_INFO(...) (std::cout << mana::LogConcat({ __VA_ARGS__ }) << '\n')
73 #endif
Definition: CodeBuffer.cpp:12
std::basic_string< MANA_CHAR > LogConcat(std::initializer_list< std::basic_string_view< MANA_CHAR >> r)
Definition: Log.h:40