log_custom - ryzom/ryzomcore GitHub Wiki


title: Custom Logging description: published: true date: 2023-03-01T05:17:26.882Z tags: editor: markdown dateCreated: 2022-03-07T11:04:17.869Z

You may want to customize the logging system directly for your own needs - include "nel/misc/log.h".

Initialization

If your program is not a "service" in the NeL terms (i.e. if it is not built on NLNET::IService), first call createDebug() to create the basic global loggers ErrorLog, WarningLog, InfoLog, DebugLog and AssertLog (the ones that are used by the nlerror, nlwarning, nlinfo, nldebug and nlassert macros).

Then, you can attach some displayers to the global loggers (NLMISC::CLog objects).

  • NLMISC::CStdDisplayer is for stdout (the console, the VC++ output window...). It is attached by default to all of the five logger objects mentionned above.
  • NLMISC::CFileDisplayer is for a file.
  • NLMISC::CMsgBoxDisplayer is for a message box.
  • NLNET::CNetDisplayer is for a logging server (see CLogService in the nelns documentation).
  • You can can create your own displayer, in order to print the logged text onto a new target (for example, see the class CChatDisplayer in Snowballs 0.2) or to customize the filter on the header.

Example (we assume CNetDisplayer allows to log via the network):

createDebug(); // automatically done in a "service"
 NLNET::CNetDisplayer *nd = new CNetDisplayer(); // the address of the Logging Server is automatically retrieved using the Naming Service
 if ( nd->connected() ) // this line is optional: here we don't want the displayer to attempt other connections if the first one failed
 {
     NLMISC::DebugLog.addDisplayer( nd );
 }

Logging Information

How do you log a string without repeating the header? You can use the methods on NLMISC::CLog.

Example:

NLMISC::DebugLog.displayNL ( "Dump of Values :" );
 for ( int j=0; j!=height; ++j )
 {
     for ( int i=0; i!=width; ++i )
     {
         NLMISC::DebugLog.displayRaw( "%d ", Values[j][i] );
     }
     NLMISC::DebugLog.displayRawNL( ": line %d", j );
 }

Source

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