CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CYBLogger.hpp
Go to the documentation of this file.
1 #pragma once
3 
4 namespace CYB {
5  namespace Engine {
7  class Logger : public API::Logger, private API::Threadable {
8  ENABLE_TEST_HOOKS
9  private:
11  struct LogEntry {
15  };
16  private:
19 
22  FFileLock;
23 
27 
28  std::atomic_bool FCancelled,
29  FDevLog,
30  FPaused;
31  private:
43  static API::String::Dynamic TimeString(const int AHour, const int AMinute, const int ASecond, const bool AColons);
52  static API::String::Dynamic TimeString(const bool AColons);
53 
64  static API::String::Dynamic FormatLogMessage(const API::String::CStyle& AMessage, const Level ALevel);
65 
92  static Platform::System::File OpenFile(void);
93 
101  static void LogShutdownForEntry(API::UniquePointer<LogEntry>&& AEntry, API::Logger& AEmergency) noexcept;
102 
109  void EmptyQueue(void);
110 
117  API::Threadable& SelfAsThreadable(void) noexcept;
118 
125  void BeginThreadedOperation(void) override;
131  void CancelThreadedOperation(void) override;
132  public:
149  Logger(API::Logger& AEmergencyLogger);
151  ~Logger();
152 
158  void Pause(void) noexcept;
164  void Resume(void) noexcept;
165 
167  void Log(const API::String::CStyle& AMessage, const Level ALevel) final override;
168 
173  void Flush(void) const noexcept final override;
174 
176  const API::String::CStyle& CurrentLog(void) const noexcept final override;
177 
179  void SetDebugLogging(const bool AEnable) noexcept final override;
180  };
181  };
182 };
void Flush(void) const noexceptfinaloverride
Delays execution until all pending logs from the current thread have been written to the output...
Definition: CYBLogger.cpp:232
Template type for wrapping pointers and treating them as objects. Only works with CyberEngine interfa...
Definition: Object.hpp:10
A memory pool manager and allocator.
Definition: CYBHeap.hpp:7
void Pause(void) noexcept
Put the logging thread to sleep.
Definition: CYBLogger.cpp:251
API::String::Dynamic FMessage
The pre-formatted text of the log.
Definition: CYBLogger.hpp:13
static API::String::Dynamic FormatLogMessage(const API::String::CStyle &AMessage, const Level ALevel)
Prepend the level and time to a log message.
Definition: CYBLogger.cpp:165
static API::String::Dynamic TimeString(const int AHour, const int AMinute, const int ASecond, const bool AColons)
Retrieve a string of the given time.
Definition: CYBLogger.cpp:8
static Platform::System::File OpenFile(void)
Prepares the logging File for writing. May block for one second if the preferred filename is taken in...
Definition: CYBLogger.cpp:60
Contains the basic File interface. Does not perform locking of any kind, be aware of possible race co...
Definition: CYBFile.hpp:6
void CancelThreadedOperation(void) override
Stops the writer thread. Does not guarantee an empty queue.
Definition: CYBLogger.cpp:161
std::atomic_bool FCancelled
Cancel flag for FThread.
Definition: CYBLogger.hpp:28
Platform::System::File FFile
The File being written to.
Definition: CYBLogger.hpp:20
Used for string of allocated variable length.
const API::String::CStyle & CurrentLog(void) const noexceptfinaloverride
Retrieve the string representation of the Path of the File the Logger is currently writing to...
Definition: CYBLogger.cpp:243
Context FContext
The Context to be used when calling the Logger.
Definition: CYBLogger.hpp:18
Level FLevel
The Level of the message.
Definition: CYBLogger.hpp:14
Platform::System::Mutex FFileLock
The lock used to acquire access to FFile.
Definition: CYBLogger.hpp:21
Memory::Heap FHeap
The isolated Heap.
Definition: CYBLogger.hpp:17
API::Interop::Object< Platform::System::Thread > FThread
The thread used for writing to the log file.
Definition: CYBLogger.hpp:26
void BeginThreadedOperation(void) override
Writer thread. Runs in a loop until CancelThreadedOperation is called.
Definition: CYBLogger.cpp:152
API::UniquePointer< LogEntry > FQueueHead
The message queue head.
Definition: CYBLogger.hpp:24
void Resume(void) noexcept
Wake the logging thread.
Definition: CYBLogger.cpp:256
A basic char contained string.
Definition: CStyleString.hpp:7
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: CYBLogger.cpp:197
The basic multithreading interface.
Definition: Threadable.hpp:6
Log entries to be inserted into the queue.
Definition: CYBLogger.hpp:11
static Platform::System::File OpenFileImpl(const Platform::System::Path &ABasePath)
Prepares the logging File for writing. May block for one second if the preferred filename is taken in...
Definition: CYBLogger.cpp:30
API::UniquePointer< LogEntry > FNext
Next item in the linked list.
Definition: CYBLogger.hpp:12
Implements the engine level functions for API::Interop::Contexts.
Definition: CYBInterop.hpp:41
The threaded, queued engine logger.
Definition: CYBLogger.hpp:7
Level
The severity of the log.
Definition: Logger.hpp:10
A fast locking, no order guaranteed, mutex.
Definition: CYBMutex.hpp:7
UniquePointer that uses our Allocator.
Used for manipulating Paths. Paths will always exist either as a file or directory. Paths are '/' delimited when forming though may not be while retrieving. File names ".." will ascend a directory and '.' represents a no-op.
Definition: CYBPath.hpp:10
static void LogShutdownForEntry(API::UniquePointer< LogEntry > &&AEntry, API::Logger &AEmergency) noexcept
Takes a LogEntry Queue and logs it out to the current given emergency logger.
Definition: CYBLogger.cpp:101
std::atomic_bool FDevLog
Flag for enabling/disabling DEV logs.
Definition: CYBLogger.hpp:28
std::atomic_bool FPaused
Flag for sleeping the logging thread.
Definition: CYBLogger.hpp:28
The interface for writing safe logs.
Definition: Logger.hpp:7
API::Threadable & SelfAsThreadable(void) noexcept
Returns the current object as a Threadable reference. Used to get around some weird VS construction i...
Definition: CYBLogger.cpp:148
void EmptyQueue(void)
Empty FQueue and write it into FFile.
Definition: CYBLogger.cpp:112
Platform::System::Mutex FQueueLock
The lock used to acquire access to FQueue.
Definition: CYBLogger.hpp:21
void SetDebugLogging(const bool AEnable) noexceptfinaloverride
Enable/Disable filtering of Level::DEV logs.
Definition: CYBLogger.cpp:247
LogEntry * FQueueTail
The message queue tail.
Definition: CYBLogger.hpp:25