Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

6.7.6.5. Custom Logging Messages

You can add custom messages that are sent to the Altera logging device. To define a custom message, include the header file alt_log_printf.h in your C source file as follows:

#include "sys/alt_log_printf.h"

Then use the following macro function:

ALT_LOG_PRINTF(const char *format, ...)

This C preprocessor macro is a pared-down version of printf(). The format argument supports most printf() options. It supports %c, %d %I %o %s %u %x, and %X, as well as some precision and spacing modifiers, such as %-9.3o. It does not support floating point formats, such as %f or %g. This function is not compiled if Altera logging is not enabled.

If you want your custom logging message to be controlled by Altera logging preprocessor options, use the appropriate Altera logging option preprocessor flags from the "ALT_LOG_FLAGS Logging Levels" table (Table 6–4), or the "Altera Logging Options and Option Modifiers" table (Table 6–3 on page 6–10).

Example 6–7. Implementing Logging Options with Custom Logging Messages

/* The following example prints "Level 2 logging message" if
logging is set to level 2 or higher */
#if ( ALT_LOG_FLAGS >= 2 )
ALT_LOG_PRINTF ( "Level 2 logging message" );
#endif
/* The following example prints "Boot logging message" if boot logging
is turned on */
#if ( ALT_LOG_BOOT_ON_FLAG_SETTING == 1)
ALT_LOG_PRINTF ( "Boot logging message" );
#endif