Learn how to log stuff in the console, inside files, and inside the editor log view

The nero_log Function

Logging is pretty useful when programming. The Engine uses the Easyloggingcpp library for logging. the default syntax looks like this :

LOG(INFO) << "log message here, this goes to the console or a file";

If you ever used that library and are familiar with it, you can still use its default syntax. A function-like syntax is easier to use, this is why the two functions nero_log() and nero_log_if() have been created to replace the original syntax. Those functions are C++ Macros, this is why they don’t use the Nero namespace.

Here is an overview of these two function :

nero_log(message, level)
nero_log_if(message, boolean)
nero_log_if(message, boolean, level)
  • message : the text you want to log
  • level : the severity of the log
  • boolean : anything that can be tested like a boolean, by example an actual boolean, a function returning a boolean, a pointer, etc.
Three levels are available, nero::Info, nero::Debug and nero::Warning. Not specifying a level is equivalent to use the logger with the level Info. The Debug and Warning level will give the File, the Line, and the Method where the logger has been called.
//calling nero_log("hello world", nero::Debug);
[DEBUG | main.cpp | Line 21 | virtual void MyScene::init() ] --> Hello world

To String Helpers

In addition to the nero_log functions, you also got some useful toString functions
  • _s(value) : converts to string and adds a space, equivalent to nero::toString(value) + nero::toString(” “)
  • _sn(object) : calls the toString method of the object, equtivalent to nero::toString(object->toString())
  • _ss(value) : “value” will not be evaluated by the compiler. By example with _ss(my_function()), my_function() will not be called, _ss() will return exactly the “my_function()”
  • _se(value) : return “value = actual_value”. By example if the float width as a value a 100.f, _se(width) will return “width = 100”
Things  are always easier with examples, so here are some :
int x = 5;
auto myPlayer = getObjectManager()->findObject("player");
nero_log("whatever", nero::Warning);
nero_log_if("whatever", x < 10); 
nero_log_if("whatever", x > 0, nero::Debug); nero_log("step : " + _s(3) + "the winner is : " + _sn(myPlayer), nero::Debug); nero_log(_ss(m_ObjectManager.findObject("player"))); nero_log(_se(x))

Log Into The Log View

Below the Render Canvas, you have the Log View. If you use the functions nero_log(), your logs will not appear inside that view.

If you want to log inside the Engine Editor you need to use your Scene log functions

void log(const std::string& content, int level = nero::Info);
void logIf(const std::string& content, bool condition, int level = nero::Info);
Those two functions are equivalent to nero_log and nero_log_if respectively. There are used exactly the same way.

Share The Scene Loggers

The two logging functions log() and logIf() of your Scene can only be used inside your Scene Class. If you want to use them anywhere else like inside your Player Class, you can retrieve them like a variable with the functions getLog() and getLogIf().

std::function<void(const std::string&, int)> getLog();
std::function<void(const std::string&, bool, int)> getLogIf();

Log Folder and Files

Inside your project directory you have a folder called log, each time the functions nero_log() and nero_log_if() or the functions log() and logIf() are called, your logs are saved permanently inside that folder.