How to enable [system] INFO log output on Boron 0.9.0?

Using the serial output via particle serial monitor and USB connection, I am unable to see [system] level INFO trace output. My code does the following:

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler(LOG_LEVEL_ALL);

void setup() {
Log.trace(“This is trace message”);
Log.warn(“This is warn message”);
Log.error(“This is error message”);
Log.info(“INFO=%d WARN=%d ERROR=%d TRACE=%d”, Log.isInfoEnabled(), Log.isWarnEnabled(), Log.isErrorEnabled(), Log.isTraceEnabled());
}

My output is:
0000005443 [app] TRACE: This is trace message
0000005443 [app] WARN: This is warn message
0000005443 [app] ERROR: This is error message
0000005444 [app] INFO: INFO=1 WARN=1 ERROR=1 TRACE=1

The question is how to enable INFO level [system] and other DeviceOS component log output?

Thought StreamLogHandler would help in setup()

auto logManager = LogManager::instance();
auto handler = new StreamLogHandler(Serial, LOG_LEVEL_ALL, {
      { "app", LOG_LEVEL_ALL },         
      { "app.main", LOG_LEVEL_ALL },    
      { "app.adc", LOG_LEVEL_ALL },      
      { "app.network", LOG_LEVEL_ALL },       
      { "system", LOG_LEVEL_ALL },         
      { "sys", LOG_LEVEL_ALL },            
      { "sys.power", LOG_LEVEL_ALL },  
      { "ncp", LOG_LEVEL_ALL },
      { "ncp.at", LOG_LEVEL_ALL },
      { "hal", LOG_LEVEL_ALL },
      { "gsm0710muxer", LOG_LEVEL_ALL },
      { "comm", LOG_LEVEL_ALL },
      { "comm.protocol", LOG_LEVEL_ALL }});
logManager->addHandler(handler);

What am I missing?

I Think its simply because there is no logging done on [system] level in the network is not connected. Did some sample code, and until the network connects at around 40s, there is no system level logging.

After that you can see the logs.

/*
 * Project SerialLogTest
 * Description:
 * Author:
 * Date:
 */
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

SerialLogHandler LogHandler(LOG_LEVEL_TRACE);

unsigned int nextTime = 0; // Next time to contact the server
int enabled = 1;

// setup() runs once, when the device is first turned on.
void setup()
{
  // Put initialization like pinMode and begin functions here.
  Log.info("Hi info");
  Particle.variable("Enabled", enabled);
  Particle.function("Logging", EnableLogging);
  Log.info("Setup done");
}

int EnableLogging(String enable)
{
  if (enable == "on")
  {
    enabled = 1;
    Log.info("Loop enabled");
  }
  else
  {
    enabled = 0;
    Log.trace("Loop disabled");
    Particle.disconnect();
  }
  return enabled;
}

// loop() runs over and over again, as quickly as it can execute.
void loop()
{
  // The core of your code will likely live here.

  if ((enabled == 0) || (nextTime > millis()))
  {
    return;
  }
  Log.info("Loop start");
  delay(500);
  Log.info("Loop end");

  nextTime = millis() + 10000;

  if ((nextTime > 40000) && (Particle.connected() == false))
  {
    Particle.connect();
  }
}

That makes sense. I actually was wondering if I needed a debug build or some other trigger to cause the components in the OS to cal Log.info / Log.trace?

BTW, the reason I’m pushing so hard to get this level of logging is due to a need to understand all threads and all power consumption. My goal is to publish every 10 minutes on a battery that does not need to be recharged more than once/year.

Please let me know your progress since im working on a Project with a similar goal, only not quite that aggressive, like every second hour.

The detailed logging from the system is only available when it’s built with DEBUG_BUILD=y. This is not the case for the released 0.9.0 binaries, and future released binaries.

Due to an odd quirk, released Electron binaries are built with DEBUG_BUILD=y. That’s why you can get the detailed modem debugging in DEBUG_LEVEL_TRACE on the Electron and E Series.

2 Likes

I assume that we can easily turn that flag on with local builds, using WorkBench, po, or just the raw toolchain. But I’m guessing we can’t enable it for the Web IDE with a #define or anything? (I’m guessing it uses pre-built binaries?)

Was about to ask the same thing. I’m using the Web IDE but would switch if it meant being able to create a debug build when needed.

You can do it with the local build chain or poutil now.

Due to a slight oversight, the Workbench “for debugging” builds don’t actually set the DEBUG_BUILD=y flag and that will be fixed in a future version. But that will be the easiest way to build a monolithic build with full trace debugging enabled in the future.

2 Likes