Serial.printlnf wrapper

I am trying to create a debug print wrapper that eventually calls the Serial.printlnf function

I am using variable args in the exact same way the Serial library uses but the parameters alway come out as garbage.

Is there any reason why the code below would not work?

void SerialPrint(E_dbgSrc Src, E_dbgDest Dst, const char \*format, ...)
{
  va_list args;

  if ( Src < dbg_Src_NumOf)
  {
    if ( DBG_ENABLE\[Src\] != false)
    {
        va_start(args, format);
        if ( Dst == dbg_Dst_USB)
        {
            Serial.printlnf(format, args);
        }
        else if ( Dst == dbg_Dst_Serial)
        {
            Serial1.printlnf(format, args);
        }
        va_end(args);
    }
  }
}

When I call this function as

SerialPrint(dbg_Src_Main, dbg_Dst_USB, "Two Arg %d, %d", 10, 1000);

I get this output

Two Arg 536964180, 536964152

The printlnf function does not take a va_list. You need to use vprintf instead.

Also you should avoid directly logging to USB serial and instead use the Log commands. If you mix the two, the device may crash because of thread safety issues. See Logging.

Unfortuatly, taht had the same affect.

To Paramters 536964164, 536964136

You may need to add the attribute specifier as well.

void SerialPrint(E_dbgSrc Src, E_dbgDest Dst, const char *format, ...)  __attribute__ ((format(printf, 3, 4)))

I tried that when I called th printlnf and it made no difference. But I can try again.