contiki-ng / cooja

This is a fork of the Cooja network simulator from contiki-os/contiki
Other
30 stars 49 forks source link

How can I get the Cooja sources code's log output? #61

Open LeoLee0097 opened 2 years ago

LeoLee0097 commented 2 years ago

Dear all, I add 3 lines in the file [contiki-ng]/tools/cooja/apps/powertracker/java/PowerTracker.java to see the timing they call the radio.isTransmitting(), radio.isReceiving() and radio.isInterfered().

public MoteTracker(Mote mote) {
      this.simulation = mote.getSimulation();
      this.mote = mote;
      this.radio = mote.getInterfaces().getRadio();
      radioWasOn = radio.isRadioOn();
      if (radio.isTransmitting()) {
        lastRadioState = RadioState.TRANSMITTING;
        log("PowerTracker - Tx\n");//Add
      } else if (radio.isReceiving()) {
        lastRadioState = RadioState.RECEIVING;
        log("PowerTracker - Rx\n");//Add
      } else if (radio.isInterfered()) {
        lastRadioState = RadioState.INTERFERED;
        log("PowerTracker - INT\n");//Add
      } else {
        lastRadioState = RadioState.IDLE;
      }
      lastUpdateTime = simulation.getSimulationTime();
      radio.addObserver(this);
    }

How could I set the log level for Cooja source files, and where could I see the log outputs?

pjonsson commented 1 year ago

If you use logger.info instead of log, the output will go to the console.

If you want that information to also be written to a file, you can pass -logfile=name.log to Cooja (so for latest master in the docker image, cooja --args="-logfile=name.log -logdir=/tmp" will write /tmp/name.log).