LoggerService

The MARTe2 LoggerService (see also Logging) enables real-time safe logging by decoupling the generation of log messages from their consumption and propagation to different outputs.

Typical LoggerService consumers include:

All LoggerConsumerI implementations accept a Format string, which defines which log properties are included in each message.

In this example, two LoggerConsumers are configured: ConsoleLogger and UDPLogger. To avoid mixing messages from different applications, the destination UDP port must be unique. This port is automatically assigned in the configuration file ../Configurations/MassSpring/RTApp-MassSpring-55.cfg via Makefile.cfg.

LoggerService configuration. The UDP destination port is automatically assigned.
 1+LoggerService = {
 2    Class = LoggerService 
 3    CPUs = 0x1
 4    +UDPLogger = {
 5        Class = UDPLogger
 6        Address = "127.0.0.1" 
 7        Port = TUTORIAL_UDP_PORT_6
 8        Format = "EtOofFRmCP" 
 9        PrintKeys = 1 
10    }
11    +ConsoleLogger = {
12        Class = ConsoleLogger
13        Format = "EtOofFRmCP" 
14        PrintKeys = 1 
15    }
16}

Tools for receiving and visualising log messages are outside the scope of this tutorial. However, an example using the marte2-log application is provided below.

Running the application

Start the application:

make -C ../Configurations/MassSpring/ -f Makefile.cfg
./MARTeApp.sh -f ../Configurations/MassSpring/RTApp-MassSpring-55_Gen.cfg -l RealTimeLoader -m StateMachine::START

Verify that the application is running correctly. The log output should look similar to:

$ |E=Warning|TM=16:55:55 (7196770772734895)|o=|O=|C=|T=|P=x86-linux|f=void MARTe::Threads::SetPriority(const ThreadIdentifier&, const MARTe::Threads::PriorityClassType&, const uint8&)|F=Threads.cpp:185|D=Failed to change the thread priority (likely due to insufficient permissions)
$ |E=Information|TM=16:55:55 (7196770772750327)|o=StateMachine|O=0x0000000001D490F0|C=StateMachine|T=|P=x86-linux|f=virtual MARTe::ErrorManagement::ErrorType MARTe::StateMachine::SendMultipleMessagesAndWaitReply(MARTe::ReferenceContainer, const MARTe::TimeoutType&)|F=StateMachine.cpp:340|D=In state (INITIAL) triggered message (StartNextStateExecutionRTApp)
$ |E=Information|TM=16:55:56 (7196771773805898)|o=|O=0x0000000001DFCAB0|C=LoggerBroker|T=|P=x86-linux|f=virtual bool MARTe::LoggerBroker::Execute()|F=LoggerBroker.cpp:152|D=Time [0:0]:990000
...
  1. Open the file ../Configurations/MassSpring/RTApp-MassSpring-55_Gen.cfg and take note of the allocated UDPLogger Port number. (Alternatively, run the command UDP_LOGGER_DEST_PORT=`awk '/\+UDPLogger/,/}/ {if ($1=="Port") print $3}' ../Configurations/MassSpring/RTApp-MassSpring-55_Gen.cfg`;echo "UDP_LOGGER_DEST_PORT=$UDP_LOGGER_DEST_PORT" to extract the port number from the configuration file).:

  2. Clone the marte2-log application and start it with the same UDP port number as the one allocated to the UDPLogger in the configuration file:

  3. Use the following command to find an available port number:

LOG_HTTP_PORT=`PORT=8080;while netstat -tln | grep -q ":$PORT"; do PORT=$((PORT + 1)); done; echo $PORT`
echo $LOG_HTTP_PORT
  1. Start the logging application in web mode:

python3.6 logapp.py -t WS -p $UDP_LOGGER_DEST_PORT -r $LOG_HTTP_PORT
  1. Open a browser and navigate to:

http://localhost:$LOG_HTTP_PORT/index.html

You should now see real-time log messages streamed from the MARTe2 application.