Skip to content

SapphireSuite/Logger

Repository files navigation

Logger

Unix Windows MacOS

Sapphire Suite's C++ Logger.
Links to the official documentation and wiki for advanced details.

Quick Use

#include <SA/Collections/Debug>

Initialization

See Initialization for advanced implementation.
No initialization is required to have simple console logging, however, a one-line initialization will provide advanced console (colors) and file logging.

// No initialization

// OR

// Single-thread (thread-unsafe) logger.
// Console Color and file logging.
SA::Debug::InitDefaultLogger();

Macros

See Macros for advanced implementation.

SA_LOG

Log anything converted as a string with default LogLevel, channel, and details.
See SA_LOG for examples and advanced use.

SA_LOG(_str, _level = Normal, _channel = Default, _details = "");

Example:

SA_LOG("Hello, World!");
[18:44:14][0] {Normal - Default}   main.cpp:50 - int main()
Msg:    Hello, World!

SA_WARN

Log a warning on false predicate with default channel and details.
See SA_WARN for examples and advanced use.

SA_WARN(_pred, _channel = Default, _details = "", _postCmd);

Example:

int myInt = 2;
SA_WARN(myInt == 1, MyChannel, "myInt invalid: might cause issues");
[18:46:20][0] {Warning - MyChannel}        main.cpp:53 - int main()
Msg:    { myInt == 1 }  evaluated to false!
Dets:   myInt invalid: might cause issues

SA_ERROR

Log an error on false predicate with default channel and details.
See SA_ERROR for examples and advanced use.

SA_ERROR(_pred, _channel = Default, _details = "", _postCmd);

Example:

int myInt = 2;
SA_ERROR(myInt == 1, MyChannel, "myInt invalid: possible crash");
[18:47:25][0] {Error - MyChannel}        main.cpp:53 - int main()
Msg:    { myInt == 1 }  evaluated to false!
Dets:   myInt invalid: possible crash

SA_ASSERT

Assert an exception built from type and parameters with default channel and details.
See SA_ASSERT for examples and advanced use.

SA_ASSERT((_excType, params...), _channel = Default, _details = "")

Example:

int myIndex = 7;
int minBound = 2;
int maxBound = 6;

// Throw SA::Exception_OutOfRange.
SA_ASSERT((OutOfRange, myIndex, minBound, maxBound), MyTestChannel, "Access index out of bound!")
[18:49:22][0] {AssertFailure - MyTestChannel}      main.cpp:53 - int main()
Msg:    Index 'myIndex' [7] is out of range ['minBound';'maxBound'] => [2;6]
Dets:   Access index out of bound!

terminate called after throwing an instance of 'SA::Exception_OutOfRange'

SA_THROW

Throw an exception built from type and parameters with default channel and details.
See SA_ASSERT for examples and advanced use.

SA_THROW((_excType, params...), _channel = Default, _details = "")

Example:

// Throw SA::Exception_ReachBadAPI.
SA_THROW((ReachBadAPI, Vulkan), Renderer.Vulkan, "Vulkan API reach with invalid object.")
[18:49:22][0] {AssertFailure - Renderer.Vulkan}      main.cpp:53 - int main()
Msg:    Reach bad [Vulkan] API call!
Dets:   Vulkan API reach with invalid object.

terminate called after throwing an instance of 'SA::Exception_ReachBadAPI'

Exceptions

The SA_ASSERT and SA_THROW macros use their own exception system. See exceptions for a list of all exceptions, how to use them, and how to extend the system (custom exception type).

Authors

Maxime "mrouffet" ROUFFET - main developer (maximerouffet@gmail.com)

Releases

No releases published

Packages

No packages published

Languages