-
Notifications
You must be signed in to change notification settings - Fork 0
Initialization
Maxime ROUFFET edited this page Mar 29, 2024
·
4 revisions
Add the subdirectory to the CMake build tree and link the library to your taget:
add_subdirectory(Logger)
target_link_libraries(<target> <link> SA_Logger)
By default, No initialization is required.
Logging using Macros will automatically output in the console (simple logging, no colors).
SA_LOG("Hello, World!");
[18:44:14][0] {Normal - Default} main.cpp:50 - int main()
Msg: Hello, World!
However, for custom implementation and advanced logging, multiple initializations are possible.
Logger callback is init by default with simple console output.
For simple custom logging, set the callback to your custom implementation:
void MyCustomLogCallback(SA::Log _log);
SA::Debug::logCB = MyCustomLogCallback;
For advanced logging with fast init, simply use:
SA::Debug::InitDefaultLogger(); // Single-thread (thread-unsafe) logger.
// OR
SA::Debug::InitDefaultLoggerThread(); // Multi-thread (safe) logger.
This will enable by default console color and file logging.
Create the Logger variable and register it to the static instance:
SA::Logger myLogger; // Single-thread (thread-unsafe) logger.
// OR
SA::LoggerThread myLogger; // Multi-thread (safe) logger.
// Register logger to static instance.
Sa::Debug::logger = &myLogger;
Add LogStreams output to the logger:
// Output to console with colors.
SA::ConsoleLogStream& cslStream = myLogger.CreateSteam<SA::ConsoleLogStream>();
// Output to file (default Log/Log.txt).
SA::FileLogStream& fileStream = myLogger.CreateSteam<SA::FileLogStream>("Log/my_log.txt");