Debug output to serial or SD card

I'm trying to create a debug function that will dump data to serial (while I'm working on the code and testing) and/or SD card (when the device is deployed). I created the following function:

void debug(String data) {
  if (state.bDebug) {
    time_t n = now();
    String entry = "";
    sprintf(entry, "%2d:%2d:%2d\t%d\t%s", hour(n), minute(n), second(n), ESP.getFreeHeap(), data);

    Serial.println(entry);

    if (state.bHasSD) {
      char* filename[20];
      sprintf(filename, "/debug/%4d%2d%2d.txt", year(n), month(n), day(n));

      File debugLog = SD.open(filename, FILE_APPEND);
      debugLog.println(entry);
      debugLog.close();
    }
  }
}

But I'm getting this error now:

error: invalid operands of types 'const char [44]' and 'const char*' to binary 'operator+'

debug("SD card detected at startup. Offline files " + ((state.bOfflineExists) ? "found":"not found"));

^

I really appreciate your help!

You can't use the + operator on string literals.

(Untested:)

const char* dbg_message = nullptr;
if(state.bOfflineExists)
{
    dbg_message = "SD card detected at startup. Offline files found";
}
else
{
    dbg_message = "SD card detected at startup. Offline files not found";
}

debug(dbg_message);

Or, with the String class:

String dbg_message;
dbg_message.reserve(64);

dbg_message =  "SD card detected at startup. Offline files "
dbg_message += (state.bOfflineExists) ? "found":"not found";