Beispiel #1
0
    /**
     * Output a variable argument list log string with the specified priority level.
     * Only defined for Arduino as depicted below.
     *
     * @param level  - DEBUG, INFO, WARNING, ERROR, FATAL
     * @param tag    - Module name
     * @param format - variadic log string
     */
    void OCLogv(LogLevel level, PROGMEM const char * tag, PROGMEM const char * format, ...)
    {
        char buffer[LINE_BUFFER_SIZE];
        va_list ap;
        va_start(ap, format);

        GET_PROGMEM_BUFFER(buffer, &(LEVEL[level]));
        Serial.print(buffer);

        char c;
        Serial.print(F(": "));

        while ((c = pgm_read_byte(tag))) {
            Serial.write(c);
            tag++;
        }
        Serial.print(F(": "));

#ifdef __AVR__
        vsnprintf_P(buffer, sizeof(buffer), format, ap);
#else
        vsnprintf(buffer, sizeof(buffer), format, ap);
#endif
        for(char *p = &buffer[0]; *p; p++) // emulate cooked mode for newlines
        {
            if(*p == '\n')
            {
                Serial.write('\r');
            }
            Serial.write(*p);
        }
        Serial.println();
        va_end(ap);
    }
Beispiel #2
0
/**
 * Output a log string with the specified priority level.
 * Only defined for Arduino.  Uses PROGMEM strings
 *
 * @param level  - DEBUG, INFO, WARNING, ERROR, FATAL
 * @param tag    - Module name
 * @param logStr - log string
 */
void OICLog(LogLevel level, PROGMEM const char * tag, PROGMEM const char * logStr)
{
    if (!logStr || !tag)
    {
        return;
    }

    char buffer[LINE_BUFFER_SIZE];

    GET_PROGMEM_BUFFER(buffer, &(LEVEL[level]));
    Serial.print(buffer);

    char c;
    Serial.print(F(": "));
    while ((c = pgm_read_byte(tag)))
    {
        Serial.write(c);
        tag++;
    }
    Serial.print(F(": "));

    while ((c = pgm_read_byte(logStr)))
    {
        Serial.write(c);
        logStr++;
    }
    Serial.println();
}