The trace feature is mainly for debugging use. You can switch between displaying and hiding traces for each type of content. Create a singleton instance of the Trace class, and then call the SetFlag() function, passing in the bitwise OR of the flags for the items you want to display.
nn::pia::common::Trace::CreateInstance();
nn::pia::common::Trace::GetInstance()->SetFlag( nn::pia::common::TRACE_FLAG_COMMON | nn::pia::common::TRACE_FLAG_SESSION ); |
The log feature is used mainly to check and keep a record of operations. By default, calling the nn::pia::common::Initialize() function implicitly creates an instance of the Log class in the Pia library. Logging features are available after this point. However, you can create your own instance of the Log class (without modifying the default instance) if you need to configure the logging features for your application. To do so, create an instance, configure it using SetMask() and other functions, and pass this instance to the Log::SetGlobalObject function.
nn::pia::common::Log log;
log.SetMask(nn::pia::common::Log::LEVEL_ERROR | nn::pia::common::log::LEVEL_WARNING); nn::pia::common::Log::SetGlobalObject(&log); |
Use the cached print feature to temporarily cache the Trace and Log console output, allowing you to delay the actual console output until any time you want. By combining multiple console outputs and reducing the number of actual console outputs, you can reduce the amount of processing consumed by console output.
To use this feature, create a singleton instance of the CachedPrint class. When you call the Flush() function at the correct time, any strings cached until then are output to the console. If the buffer for the cache runs out of room, earlier strings are overwritten. If some strings are not output, either increase the size of the buffer or increase the frequency at which the Flush() function is called.
When the CachedPrint singleton instance has not been created, Trace and Log output to the console as they normally would.
const size_t CACHED_PRINT_BUFFER_SIZE = 32 * 1024;
nn::pia::common::CachedPrint::CreateInstance(CACHED_PRINT_BUFFER_SIZE); nn::pia::common::CachedPrint::GetInstance()->Flush(); |
If you want to cache while an application is printing as you would cache in Pia, you can print using the PIA_CACHED_PRINTF() and PIA_CACHED_VPRINTF() macros.
The SetPrintTime() function is available for both the Log class and the Trace class. If you call these functions with the true argument specified, the time that has elapsed since the base time is output in milliseconds at the same time that the log and trace are output.
nn::pia::common::Trace::GetInstance()->SetPrintTime(true);
|
The print hook feature is provided for debugging.
You can use this feature to process console output from Pia in the application or implement a feature that draws the console output to the screen.
// The callback function to hook. The function must have a type of nn::pia::common::InternalPrintCallback.
void myCallback(const char* pStr, s32 len) { const size_t SZ = 80; char buf[SZ]; const char* p = pStr; while(p < pStr + len) { strncpy(buf, p, SZ-1); buf[SZ-1] = '\0'; drawText(buf); // Draw the text to the screen. p += (SZ-1); } } // Function to set as the callback. void setPrintHookCallback() { nn::pia::common::RegisterInternalPrintCallback(myCallback); } |