log - ryzom/ryzomcore GitHub Wiki


title: Logging description: published: true date: 2023-03-01T05:16:29.923Z tags: editor: markdown dateCreated: 2022-03-07T10:47:48.765Z

The debugging system allows to log information at various levels. To get started you will want to include the header file "nel/misc/debug.h". This header contains all of the macros necessary to begin logging. The logging facilities provide five different logging levels: Error, Warning, Info, Debug and Assert. Each logging level can be accessed using it's associated logging macro. Each of these will take an expression (denoted by exp in the table below) and this expression is typically in the format that is passed to function printf.

Logging Method Log Level Description
nlerror(exp) Error This method always logs to ErrorLog. Once completed logging it will throw the EFatalError exception. This must be in a try/catch block.
nlerrornoex(exp) Error This method always logs to ErrorLog. Unlike nlerror, this method does not throw an exception. It simply exits the application. This is typically used in a catch block.
nlwarning(exp) Warning In RELEASE mode this method does nothing. In all other modes this method logs to the WarningLog. The parameter exp is in printf syntax.
nlinfo(exp) Info In RELEASE mode this method does nothing. In all other modes this method logs to the InfoLog. The parameter exp is in printf syntax.
nldebug(exp) Debug In RELEASE mode this method does nothing. In all other modes this method logs to the DebugLog. The parameter exp is in printf syntax.
nlassert(exp) Assert In RELEASE mode this does nothing. In all other modes if the expression is false, it will log and then abort().
nlassertonce(exp) Assert In RELEASE mode this does nothing. In all other modes if the expression is false, it will log and then abort(). This will only execute once in a loop.
nlassertex(exp,str) Assert In RELEASE mode this does nothing. In all other modes if the expression is false, it will log the parameter str and then abort().
nlverify(exp) Assert In RELEASE mode this executes exp and nothing more. Otherwise this is the same as nlassert.
nlverifyonce(exp) Assert In RELEASE mode this executes exp and nothing more. Otherwise this is the same as nlassertonce.
nlverifyex(exp,str) Assert In RELEASE mode this executes exp and nothing more. Otherwise this is the same as nlassertex.

As you can see above these methods allow you to display strings variable arguments such as if you were using the printf function. In the default behavior, the text passed to these macros is displayed into STDOUT except in RELEASE mode. The text logged is also written into a file called "log.log" in the working directory. These macros print the strings with an information header.

Example:

sint32 age = -2;
nldebug( "Toto is %d years old", age );
if ( age < 0 )
{
	nlerror( "Invalid age for toto : %d", age );

	// the program will not come here because nlerror throws an exception to exit
}

STDOUT (logger thread_id file line: debug_string):

DBG 1234 myfile.cpp 10: Toto is -2 years old
ERR 1234 myfile.cpp 13: Invalid age for toto : -2
Abort

FILE OUTPUT (date time logger debug_string):

01/04/11 18:24:50 DBG: Toto is -2 years old
01/04/11 18:24:50 ERR: Invalid age for toto : -2

Because NeL allows you to create multi-threaded programs these macros use mutual exclusions (mutex) to ensure no data is corrupted and the displayed text not interlaced. You will become very familiar with using the nlinfo macro as it is the most commonly used macro.

Source

⚠️ **GitHub.com Fallback** ⚠️