CyberEngineMkIII
|
The threaded, queued engine logger. More...
#include <CYBLogger.hpp>
Classes | |
struct | LogEntry |
Log entries to be inserted into the queue. More... | |
Public Member Functions | |
Logger (API::Logger &AEmergencyLogger) | |
Initializes and starts the Logger. Changes the current Context. May block for one second if the preferred file name is taken in order to generate a new one. More... | |
~Logger () | |
Shutdown the Logger and empty the queue. | |
void | Pause (void) noexcept |
Put the logging thread to sleep. More... | |
void | Resume (void) noexcept |
Wake the logging thread. More... | |
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. More... | |
void | Flush (void) const noexceptfinaloverride |
Delays execution until all pending logs from the current thread have been written to the output. More... | |
const API::String::CStyle & | CurrentLog (void) const noexceptfinaloverride |
Retrieve the string representation of the Path of the File the Logger is currently writing to. More... | |
void | SetDebugLogging (const bool AEnable) noexceptfinaloverride |
Enable/Disable filtering of Level::DEV logs. More... | |
Private Member Functions | |
void | EmptyQueue (void) |
Empty FQueue and write it into FFile. More... | |
API::Threadable & | SelfAsThreadable (void) noexcept |
Returns the current object as a Threadable reference. Used to get around some weird VS construction issues. More... | |
void | BeginThreadedOperation (void) override |
Writer thread. Runs in a loop until CancelThreadedOperation is called. More... | |
void | CancelThreadedOperation (void) override |
Stops the writer thread. Does not guarantee an empty queue. More... | |
Static Private Member Functions | |
static API::String::Dynamic | TimeString (const int AHour, const int AMinute, const int ASecond, const bool AColons) |
Retrieve a string of the given time. More... | |
static API::String::Dynamic | TimeString (const bool AColons) |
Retrieve a string of the current time. More... | |
static API::String::Dynamic | FormatLogMessage (const API::String::CStyle &AMessage, const Level ALevel) |
Prepend the level and time to a log message. More... | |
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 order to generate a new one. More... | |
static Platform::System::File | OpenFile (void) |
Prepares the logging File for writing. May block for one second if the preferred filename is taken in order to generate a new one. More... | |
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. More... | |
Private Attributes | |
Memory::Heap | FHeap |
The isolated Heap. | |
Context | FContext |
The Context to be used when calling the Logger. | |
Platform::System::File | FFile |
The File being written to. | |
Platform::System::Mutex | FQueueLock |
The lock used to acquire access to FQueue. | |
Platform::System::Mutex | FFileLock |
The lock used to acquire access to FFile. | |
API::UniquePointer< LogEntry > | FQueueHead |
The message queue head. | |
LogEntry * | FQueueTail |
The message queue tail. | |
API::Interop::Object < Platform::System::Thread > | FThread |
The thread used for writing to the log file. | |
std::atomic_bool | FCancelled |
Cancel flag for FThread. | |
std::atomic_bool | FDevLog |
Flag for enabling/disabling DEV logs. | |
std::atomic_bool | FPaused |
Flag for sleeping the logging thread. | |
Additional Inherited Members | |
![]() | |
enum | Level : byte { Level::DEV, Level::INFO, Level::WARN, Level::ERR } |
The severity of the log. More... | |
The threaded, queued engine logger.
Definition at line 7 of file CYBLogger.hpp.
CYB::Engine::Logger::Logger | ( | API::Logger & | AEmergencyLogger | ) |
Initializes and starts the Logger. Changes the current Context. May block for one second if the preferred file name is taken in order to generate a new one.
AEmergencyLogger | The Logger to write errors to if this one fails |
Definition at line 66 of file CYBLogger.cpp.
|
overrideprivatevirtual |
Writer thread. Runs in a loop until CancelThreadedOperation is called.
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::STREAM_NOT_WRITABLE. Thrown if the log File could not be written to |
Implements CYB::API::Threadable.
Definition at line 152 of file CYBLogger.cpp.
|
overrideprivatevirtual |
Stops the writer thread. Does not guarantee an empty queue.
Implements CYB::API::Threadable.
Definition at line 161 of file CYBLogger.cpp.
|
finaloverridevirtualnoexcept |
Retrieve the string representation of the Path of the File the Logger is currently writing to.
Implements CYB::API::Logger.
Definition at line 243 of file CYBLogger.cpp.
|
private |
Empty FQueue and write it into FFile.
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::STREAM_NOT_WRITABLE. Thrown if the log File could not be written to |
Definition at line 112 of file CYBLogger.cpp.
|
finaloverridevirtualnoexcept |
Delays execution until all pending logs from the current thread have been written to the output.
Implements CYB::API::Logger.
Definition at line 232 of file CYBLogger.cpp.
|
staticprivate |
Prepend the level and time to a log message.
AMessage | The message to format |
ALevel | The Level of AMessage |
AMessage
prepended with the current time and Level string CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::HEAP_ALLOCATION_FAILURE. Thrown if the current heap runs out of memory |
CYB::Exception::Violation | Error code: CYB::Exception::Violation::INVALID_ENUM. Thrown if the ALevel is invalid |
Definition at line 165 of file CYBLogger.cpp.
|
finaloverridevirtual |
Log a message. Will be written to a text file on the Path returned by CurrentLog.
AMessage | The message to log |
ALevel | The Level of the message |
CYB::Exception::Violation | Error code: CYB::Exception::Violation::INVALID_ENUM. Thrown if the ALevel is invalid In the near impossible case that the isolated Heap the Logger uses runs out of memory, this function will block and flush the write queue to free space This function may silently fail in the case that the log cannot be written to |
Implements CYB::API::Logger.
Definition at line 197 of file CYBLogger.cpp.
|
staticprivatenoexcept |
Takes a LogEntry Queue and logs it out to the current given emergency logger.
AEntry | An xvalue of a LogEntry. All its contents will be logged and deleted |
AEmergency | the current emergency logger |
Definition at line 101 of file CYBLogger.cpp.
|
staticprivate |
Prepares the logging File for writing. May block for one second if the preferred filename is taken in order to generate a new one.
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::STREAM_NOT_WRITABLE. Thrown if the log File could not be opened |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::SYSTEM_PATH_RETRIEVAL_FAILURE. Thrown if the temporary Path could not be retrieved |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::STREAM_NOT_READABLE. Thrown if Path errors occured while setting up the file |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::PATH_TOO_LONG. Thrown if the new Path would exceed the limitation |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::PATH_LOST. Thrown if Path errors occured while setting up the file Theoretically this could throw CYB::Exception::SystemData::HEAP_ALLOCATION_FAILURE on some string allocations, but given the initial empty Heap this is practically impossible |
Definition at line 60 of file CYBLogger.cpp.
|
staticprivate |
Prepares the logging File for writing. May block for one second if the preferred filename is taken in order to generate a new one.
ABasePath | A Path to the directory to log in |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::STREAM_NOT_WRITABLE. Thrown if the log File could not be opened |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::SYSTEM_PATH_RETRIEVAL_FAILURE. Thrown if the temporary Path could not be retrieved |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::STREAM_NOT_READABLE. Thrown if Path errors occured while setting up the file |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::PATH_TOO_LONG. Thrown if the new Path would exceed the limitation |
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::PATH_LOST. Thrown if Path errors occured while setting up the file Theoretically this could throw CYB::Exception::SystemData::HEAP_ALLOCATION_FAILURE on some string allocations, but given the initial empty Heap this is practically impossible |
Definition at line 30 of file CYBLogger.cpp.
|
noexcept |
Put the logging thread to sleep.
Definition at line 251 of file CYBLogger.cpp.
|
noexcept |
Wake the logging thread.
Definition at line 256 of file CYBLogger.cpp.
|
privatenoexcept |
Returns the current object as a Threadable reference. Used to get around some weird VS construction issues.
Definition at line 148 of file CYBLogger.cpp.
|
finaloverridevirtualnoexcept |
Enable/Disable filtering of Level::DEV logs.
AEnable | Enables DEV logs if true, disables them otherwise |
Implements CYB::API::Logger.
Definition at line 247 of file CYBLogger.cpp.
|
staticprivate |
Retrieve a string of the given time.
AHour | The hour to display |
AMinute | The minute to display |
ASecond | The second to display |
AColons | If true, print with brackets and colons. Otherwise use dashes |
AColons
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::HEAP_ALLOCATION_FAILURE. Thrown if the current heap runs out of memory |
Definition at line 8 of file CYBLogger.cpp.
|
staticprivate |
Retrieve a string of the current time.
AColons | If true, print with brackets and colons. Otherwise use dashes |
AColons
CYB::Exception::SystemData | Error code: CYB::Exception::SystemData::HEAP_ALLOCATION_FAILURE. Thrown if the current heap runs out of memory |
Definition at line 23 of file CYBLogger.cpp.