Using SerialLogHandler makes the Photon disappear from USB serial

I’m trying to debug some irritating crash issues, and I was hoping to get some logging out of the Photon via USB Serial. However, if I use the SerialLogHandler, the Photon disappears from my list of serial ports. I’m on Mac OS X El Capitan.

This works:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("loop");
}

However, the following does not:

void setup() {
  SerialLogHandler handler(LOG_LEVEL_TRACE);
}

void loop() {
  Log.trace("loop");
}

If I flash the device with the above code, the serial device ( /dev/cu.usbmodem1411) disappears from the list visible in the Dev serial monitor. I’ve tried a few different serial monitors, including the Photon CLI tools, and all of them report that the device just isn’t there.

Is there something I’m missing? Should I be instantiating the handler differently? Am I completely misunderstanding how the SerialLogHandler works?

Ugh, stupid mistake. I just need to declare the handler outside the setup function.

SerialLogHandler handler(LOG_LEVEL_TRACE);
void setup() {
}

void loop() {
  Log.trace("loop");
}
1 Like

Thank you for posting your answer!