CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CYBConsole.cpp
Go to the documentation of this file.
1 #include "CYB.hpp"
3 
4 #include <ctime>
5 #include <cstring>
6 
8  FConsolePath(u8"stdout/stderr"),
9  FDevLog(false)
10 {}
11 
12 void CYB::Platform::System::Console::Log(const API::String::CStyle& AMessage, const Level ALevel) {
13  if (ALevel != Level::DEV || FDevLog.load(std::memory_order_relaxed)) {
14  const char* LevelString;
15  bool IsError(false);
16  switch (ALevel) {
17  case Level::DEV:
18  LevelString = ": Debug: ";
19  break;
20  case Level::INFO:
21  LevelString = ": Info: ";
22  break;
23  case Level::WARN:
24  LevelString = ": Warning: ";
25  break;
26  case Level::ERR:
27  LevelString = ": ERROR: ";
28  IsError = true;
29  Show();
30  break;
31  default:
33  }
34  auto Time(time(0)); // get time now
35  auto Now(localtime(&Time));
36  const auto Hour(Now->tm_hour), Min(Now->tm_min), Sec(Now->tm_sec);
37  char Buffer[50];
38  memset(Buffer, 0, 50); //memset instead of Buffer[Length] = 0 because coverage
39 
40  const auto Length(sprintf(Buffer, u8"[%02d:%02d:%02d]", Hour, Min, Sec));
41 
42  API::Assert::LessThan(-1, Length);
43  API::Assert::LessThan(Length, 50);
44 
45  API::LockGuard Lock(FLock);
46  WriteOut(API::String::Static(Buffer), IsError);
47  WriteOut(API::String::Static(LevelString), IsError);
48  WriteOut(AMessage, IsError);
49  WriteOut(API::String::Static("\n"), IsError);
50  }
51 }
52 
53 void CYB::Platform::System::Console::Flush(void) const noexcept {}
54 
56  return FConsolePath;
57 }
58 
59 void CYB::Platform::System::Console::SetDebugLogging(const bool AEnable) noexcept {
60  FDevLog.store(AEnable, std::memory_order_release);
61 }
const API::String::CStyle & CurrentLog(void) const noexceptfinaloverride
Returns the console path.
Definition: CYBConsole.cpp:55
void SetDebugLogging(const bool AEnable) noexceptfinaloverride
Enable/Disable filtering of Level::DEV logs.
Definition: CYBConsole.cpp:59
A RAII locking mechanism.
Definition: LockGuard.hpp:7
A string pointing to unchanging data in the stack above it or the data segment. Must have UTF-8 encod...
Definition: StaticString.hpp:7
static void LessThan(const AType &ALHS, const AType &ARHS) noexcept
Less than assertion function. May not be evaluated.
Console()
Contructs a console interface and sets up the fake Path and Logger.
Definition: CYBConsole.cpp:7
A basic char contained string.
Definition: CStyleString.hpp:7
Precompiled header for inter-engine operations.
Level
The severity of the log.
Definition: Logger.hpp:10
void Flush(void) const noexceptfinaloverride
Delays execution until all pending logs from the current thread have been written to the output...
Definition: CYBConsole.cpp:53
void Log(const API::String::CStyle &AMessage, const Level ALevel) finaloverride
Log a message. Will be written to a text file on the Path returned by CurrentLog. ...
Definition: CYBConsole.cpp:12
Exceptions indicating an API contract violation. Should not be anticipated.
Definition: Exception.hpp:32
An operation was attempted with an invalid enum code.
Definition: Exception.hpp:36