Device Logs over UDP
Developing applications requires debugging and in most embedded projects this means writing to a logger. Meadow is no different here. If you’re familiar with Meadow development, you’re probably familiar with calling the various methods on Resolver.Log
but you might wonder why we recommend you use Resolver.Log
instead of just Console.WriteLine
(which is what the default Resolver.Log
calls do).
One feature Resolver.Log
provides is the concept of a LogLevel
. Your application can log to different levels (Trace
, Debug
, Info
, Warning
and Error
) and then you can tell the logger to suppress output below a certain level to increase or decrease output chatter. Basically, it’s added an if
condition around Console.WriteLine
for you.
Another feature of the Resolver.Log
that is not as obvious is that it holds a list of ILogProviders
and you can add to that list. By default, you get a ConsoleLogProvider
that, as the name suggests, logs to the Console. But you can add additional providers to provide any other type of logging that you might want. Creating your own implementation is straightforward, but we provide a couple additional Providers in the Meadow.Logging.LogProviders
(available on NuGet or as source in GitHub) library that are not just good examples of how to implement them, they can be pretty useful right out of the box.
In some situations, it’s pretty inconvenient to need a USB cable connected between your development PC and the Meadow to see what’s happening, for example, if you’ve put it into an enclosure to do integration or field testing, but you still would like to see that log information. What if you could look at the Logger
output over the network instead? This is exactly what the UdpLogger is for!
To use the UdpLogger
you simply add an instance of the provider to the Resolver.Log
after the Meadow has connected with the network.
// wait for the network to connect
wifi.NetworkConnected += (s, e) =>
{
// add a UdpLogger to the Log Providers
Resolver.Log.AddProvider(new UdpLogger());
};
Now, any time your application calls a Resolver.Log
method, the message will be routed to the Console and broadcast over UDP. You can then watch those messages from any other device on the network using a tool like Wireshark or the simple Console UDP client we provide source for.
As Meadow grows in maturity, we’re working hard to provide tools to accelerate your solution development and debugging tools like LogProviders
can save you hours of time and frustration. The Meadow.Logging.LogProviders
library currently provides implementations to broadcast over UDP or to write to a local file (helpful for storing warnings and errors).
Join our Slack community to let us know if you find these helpful, and/or if there are others that would help you ship faster.