Logging for Testing and Production Mode

In this tutorial, we will go over several options for logging data during testing and debugging, but also how logging can be used by deployed production-ready products.

As explained in the introductory tutorial, under the section Understanding the Xedge32 Ecosystem, the Barracuda App Server (BAS) is the foundation for Xedge, which in turn is the foundation for Xedge32. In this tutorial, we will use an Xedge32-powered ESP32 to show how it works, but the tutorial applies to any BAS-powered device.

print(string, ...) -- BAS API
trace(string, ...) -- BAS API
tracep([info,] priority, string, ...) -- BAS API
xedge.elog(op, formatstring, ...) -- Xedge API
xedge.eflush([op]) -- Xedge API

-- Examples:

-- Function print, trace, and tracep convert all arguments to strings
trace("Socket obj:", ba.socket.connect("realtimelogic.com",80))

-- Uses the same format string as the Lua function string.format
xedge.elog({}, "%s %d", "The Answer to the Ultimate Question of Life is", 42)

See the documentation for print,trace,tracep and xedge.elog for details.

Function print, which comes from the Lua API, prints data to the console. However, in a BAS-powered environment, this function, if used from a non LSP page, may not be enabled if the device has no console. When using Xedge32, the output from this function is sent to the trace library. Function trace and tracep send data to BAS’s trace library. The trace library includes a porting layer that, for Xedge32 sends data to the UART serial connection. Function xedge.elog is an Xedge-specific logging function that either sends the message as an email or sends it to the trace library.


The above functions also send data to the TraceLogger, a WebSocket endpoint a TraceLogger client can connect to and receive data from. The Xedge IDE includes a TraceLogger client in the bottom pane. You may also navigate directly to the TraceLogger client by navigating to http://xedge32.local/rtl/tracelogger/.

TraceLogger Web Client

The TraceLogger Web Client is a JavaScript-powered app that connects to your device using WebSockets. Trace data from the device is then sent over WebSockets to the HTML UI.

TraceLogger Web Client

Using the TraceLogger Web Client, the trace priority (trace level) can be changed. You can also programmatically change the trace level by controlling the object returned by function ba.create.tracelogger(). When using Xedge, the TraceLogger object is created by the startup code, thus calling ba.create.tracelogger() returns the already created object. The default trace priority set in Xedge is 9.

The trace level for function print and trace is set to zero, the highest priority level. Function xedge.elog’s level is set to 5. Function tracep lets you select any level.

The links below will take you to our online Lua tutorial server, where you can directly interact with the TraceLogger integrated into the Xedge IDE as well as the standalone TraceLogger.

Note that the TraceLogger supports a single active client connection. Should you encounter an error indicating that the TraceLogger is currently in use, you have the option to override this by forcibly disconnecting the existing client and establishing your own connection.

How to Save the Trace File on Your Host Computer

The Mako Server, Xedge32’s big brother, can be used as a TraceLogger client. The benefit of using this option is that it enables a more permanent option for receiving log data from the device. When the Mako Server is installed as a background process, the data received over the network from the device is saved in mako.log, the Mako Server's log buffer. In addition, the Mako Server’s TraceLogger Web Client will show log data in real-time as it trickles in from the device.

Download the Mako Server and the Mako Server’s TraceLogger Client to use this logging option.

For long-term logging, consider installing the Mako Server and the Mako Server’s TraceLogger client on for example, a Raspberry Pi.

Introduction to Email Logging in Xedge

Email notifications may feel old-school, but they're handy, both during development and after your product hits the market. That's why Xedge includes a straightforward email logging feature. Configure SMTP in Xedge, and voilà - crucial updates land directly in your inbox.

Why Enable Email Logging?

Email logging acts as your Xedge device's guardian, offering several key benefits:

  • Immediate Exception Alerts: Nobody's perfect, and if your Lua program encounters an error, it gets logged to the trace buffer, but with email logging, Xedge takes it a step further by dispatching a detailed exception report to your designated email. This means you're informed in real time about crashes, enabling continuous monitoring of your products.
  • Programmatic Notifications: Need tailored alerts? The xedge.elog() function lets you craft email notifications triggered by specific events in your Lua scripts. This can be invaluable for receiving updates on critical events or data points you've determined to be important.
  • Efficient Message Handling: Xedge respects your inbox. Non-urgent messages are intelligently batched together and sent when they reach a specific size or after a specified time interval. This bulk sending ensures you receive updates without being overwhelmed by a flood of separate emails.
  • Emergency Flush Capability: For urgent matters, Xedge can bypass the batching process and send an immediate alert using the flush attribute. This ensures that the most critical information reaches you without any delay.
  • Smart Disable Feature: Xedge is smart about when to send emails. Email messaging is automatically turned off when a browser is actively connected to the Xedge IDE, preventing unnecessary email traffic when actively developing code.

Configuring the Email SMTP Settings

The tutorial Xedge SMTP Settings explains in detail how to configure SMTP and send emails.

Looking for Guidance?

Unlock the potential of embedded web servers and IoT with our curated tutorials. They're your DIY toolkit for success. But if you're racing against the clock or need a deeper perspective, our expert consulting services are your ace in the hole. With Real Time Logic, you're never alone on your DIY journey. Let's collaborate and make magic happen!


OPC-UA Client & Server

An easy to use OPC UA stack that enables bridging of OPC-UA enabled industrial products with cloud services, IT, and HTML5 user interfaces.

Edge Controller

Edge Controller

Use our user programmable Edge-Controller as a tool to accelerate development of the next generation industrial edge products and to facilitate rapid IoT and IIoT development.

On-Premises IoT

On-Premises IoT Platform

Learn how to use the Barracuda App Server as your On-Premises IoT Foundation.

Embedded Web Server

Barracuda Embedded Web Server

The compact Web Server C library is included in the Barracuda App Server protocol suite but can also be used standalone.

WebSocket Server

Microcontroller Friendly

The tiny Minnow Server enables modern web server user interfaces to be used as the graphical front end for tiny microcontrollers. Make sure to check out the reference design and the Minnow Server design guide.

WebDAV Server

Network File System

Why use FTP when you can use your device as a secure network drive.

HTTP Client

Secure HTTP Client Library

PikeHTTP is a compact and secure HTTP client C library that greatly simplifies the design of HTTP/REST style apps in C or C++.

WebSocket Client

Microcontroller Friendly

The embedded WebSocket C library lets developers design tiny and secure IoT applications based on the WebSocket protocol.

SMTP Client

Secure Embedded SMTP Library

Send alarms and other notifications from any microcontroller powered product.

Crypto Library

RayCrypto C Library

The RayCrypto engine is an extremely small and fast embedded crypto library designed specifically for embedded resource-constrained devices.

Embedded PKI Service

Automatic SSL Certificate Management for Devices

Real Time Logic's SharkTrust™ service is an automatic Public Key Infrastructure (PKI) solution for products containing an Embedded Web Server.


Modbus TCP client

The Modbus client enables bridging of Modbus enabled industrial products with modern IoT devices and HTML5 powered HMIs.

Posted in Whitepapers