61
SFML projects / Re: Nero Game Engine
« on: March 26, 2018, 10:56:50 pm »
How to code with the Engine Part 1-1 : The nero logger
Log things is pretty useful when programming, this is why I wanted to start this series of Howtos with the logger.
The Engine use the Easyloggingcpp library for logging. the default synthax look like this
[ LOG(INFO) << "log message here, this goes to the console" ]
If you ever used that library and are familiar with it, you can still use its default synthax.
I prefer function-like synthax, this is why I design the [ nero_log() ] and [ nero_log_if() ] functions to replace the original synthax. Those functions are in fact Macros, this is why they don't use the nero namepsace.
Here is a overview of these two functions
Two levels are availabled. Not specifing a level is equivalent to use the logger in INFO level
In addition to the logger Macros, you also got some toString Macros
Things are always more easy with examples, so here are some
Log things is pretty useful when programming, this is why I wanted to start this series of Howtos with the logger.
The Engine use the Easyloggingcpp library for logging. the default synthax look like this
[ LOG(INFO) << "log message here, this goes to the console" ]
If you ever used that library and are familiar with it, you can still use its default synthax.
I prefer function-like synthax, this is why I design the [ nero_log() ] and [ nero_log_if() ] functions to replace the original synthax. Those functions are in fact Macros, this is why they don't use the nero namepsace.
Here is a overview of these two functions
nero_log(message)
nero_log(message, level)
nero_log_if(message, boolean)
nero_log_if(message, boolean, level)
nero_log(message, level)
nero_log_if(message, boolean)
nero_log_if(message, boolean, level)
Two levels are availabled. Not specifing a level is equivalent to use the logger in INFO level
nero::Debug
nero::Warning
//The Debug and Warning level will give the File, the Line and the Method where the log has been called
[DEBUG | main.cpp | Line 21 | virtual void MyScene::init() ] --> Hello world
nero::Warning
//The Debug and Warning level will give the File, the Line and the Method where the log has been called
[DEBUG | main.cpp | Line 21 | virtual void MyScene::init() ] --> Hello world
In addition to the logger Macros, you also got some toString Macros
_s(value)
//equivalent to nero::toString(value), it automatically add a space at the end.
_sn(object)
//call the toString method of the object, equtivalent to object->toString()
//equivalent to nero::toString(value), it automatically add a space at the end.
_sn(object)
//call the toString method of the object, equtivalent to object->toString()
Things are always more easy with examples, so here are some
x = 5;
auto myPlayer = m_ObjectManager.findObject("player");
nero_log("whatever");
nero_log("whatever", nero::Warning);
nero_log_if("whatever", x < 10);
nero_log_if("whatever", x > 0, nero::Debug);
nero_log("step : " + _s(10) + "the winner is : " + _sn(myPlayer), nero::Debug);
auto myPlayer = m_ObjectManager.findObject("player");
nero_log("whatever");
nero_log("whatever", nero::Warning);
nero_log_if("whatever", x < 10);
nero_log_if("whatever", x > 0, nero::Debug);
nero_log("step : " + _s(10) + "the winner is : " + _sn(myPlayer), nero::Debug);