/** * Report a message to the Logging service. On the linux emulator * this will end up going to stdout. On the Zaurus device it will * be written to a file. * * The <code>message</code> parameter is treated as a format * string to the standard C library call printf would be, with * conversion specifications (%s, %d, %c, etc) causing the * conversion and output of each successive argument after * <code>message</code> As with printf, having a conversion * character in <code>message</code> without an associated argument * following it is an error. * * To ensure that no character in <code>message</code> is * interpreted as requiring conversion, a safe way to call * this method is: * <code> reportToLog(severity, chanID, "%s", message); </code> * @param severity severity level of report * @param channelID area report relates to, from midp_constants_data.h * @param message detail message to go with the report * should not be NULL */ void reportToLog(int severity, int channelID, char* message, ...) { va_list ap; if (!fChannelSetupDone) { /* * Get the system property to check if the specific * channels were set for logging. */ const char* pChannelsArg = getSystemProperty(LOG_CHANNELS_ARG); if (pChannelsArg) { createLogChannelsList(pChannelsArg); } fChannelSetupDone = 1; } if (message != NULL && channelInList(channelID)) { midp_snprintf(gLoggingBuffer, LOGGING_BUFFER_SIZE, "REPORT: <level:%d> <channel:%d> ", severity, channelID); pcsl_print(gLoggingBuffer); va_start(ap, message); midp_vsnprintf(gLoggingBuffer, LOGGING_BUFFER_SIZE, message, ap); pcsl_print(gLoggingBuffer); va_end(ap); pcsl_print("\n"); } }
/** * Not all compilers provide snprintf function, so we have * to use workaround. In debug mode it does buffer overflow * checking, and in release mode it works as sprintf. */ int midp_snprintf(char* buffer, int bufferSize, const char* format, ...) { va_list argptr; int rv; /* * To prevent warning about unused variable when * not checking for overflow */ (void)bufferSize; va_start(argptr, format); rv = midp_vsnprintf(buffer, bufferSize, format, argptr); va_end(argptr); return rv; }