Logging from Game Engines, Part Two: Logging in the Corona SDK

 

Logging From Corona Blog Header

In my last article, I provided an overview of how to send logs from the Unity Engine to Loggly in order to get live log data from end-user’s clients and quickly diagnose and solve issues before users find them. Today, we will look at doing the same for Corona SDK, another favorite game engine for creating mobile games.

Logging Versus Debugging in Corona

Corona exclusively uses the Lua language, one of the most commonly used scripting languages in the game industry. Therefore, most of Corona’s debugging functionality is limited to the Corona debugger and writing log statements into log files and the Corona console. This leads to the same problem we saw with Unity: Having no available data on live clients post-deployment. Luckily, Corona can also send remote logs to Loggly or another cloud-based log management service.

How to Send Corona Logs to Loggly

For Corona, the best method for sending logs to Loggly is to send them directly via the Loggly REST API. This is a very simple task in the Corona SDK due to its usage of the Lua language.

Logging via HTTP POST Methods

Like Unity, the Corona SDK has the ability to send logs via HTTP using the network.request() method. Again, it’s always best to send messages to Loggly in JSON, and one of the nicer things about Corona is that key-value pairs in Lua tables map almost one-to-one with the structure of JSON.

For instance, a Lua table look like this.

The same data in JSON looks like this, which makes sending logs from Corona quite easy.

So let’s give a quick code example of how to send an event to loggly with Corona.

In short, all you need to do is:

  • Encode a Lua table with key-value pairs into JSON using Corona’s JSON.encode method
  • Send directly via HTTP with Corona’s network.request method

Logging Crashes: Sending Corona SDK Stack Traces

When Corona crashes, it provides a stack trace to the Corona console. These stack traces important to log. Corona also provides the ability to for developers to add a runtime event to capture this stack trace and do anything they wish with that information. Let’s look at how this would be done.

Five Corona Logging Tips

When you’re logging in Corona, here are a few things that are really important to note.

  1. Always use key-value pairs and ensure your values are only of type string, number, or another nested table. No boolean or function types.
  2. If you’re making an app for mobile devices, ensure you’re requesting permission to use the basic Internet functionality of the devices to which you’re deploying.
  3. Just like JSON, you can nest tables as long as you enforce the data type and key-value restriction above. For example:
  4. Create a logging controller file that can be referenced by any Lua file you create for the game. That way, you can easily insert logging into any place you may need it.
  5. Unfortunately, there are no logging frameworks like log4j available for Lua, so there’s no out-of-the-box way to automatically log system-level messages (such as INFO, WARN, ERROR, FATAL). However, you should specify logging levels in your messages in order to keep your data neat.

Logging from Corona: The End Result

Once you have successfully started sending logs to Loggly using the methods described above, you will have access to your logs via a centralized interface. You’ll be able to analyze them much more efficiently using Loggly Dynamic Field ExplorerTM (shown below), and you’ll be able to take advantage of all of the other handy troubleshooting capabilities of Loggly.

Logging From Corona in Loggly

Is your app experiencing regular crashes? You can drill down to see not only the crashes but also the events that led up to them. Furthermore, you will be able to visualize all events with custom charts that help you spot trends. You’ll be able to set custom alerts to notify your developers when bugs or other performance issues have occurred, so that they can immediately get to work on them.

Once Loggly is integrated in your live game project, you should notice an almost instant change in how quickly you find and diagnose issues and how much more you know about how your game operates. Signup is free, so I urge you to try it out!

ps. If you already using Corona, you can get up and running with logging immediately with my logging controller library at: https://github.com/CharmedMatter/CoronaSDK_LogtoLoggly/


Mike Turner is a partner in Charmed Matter Games, a full pipeline a small development studio founded by several veteran online & mobile online game developers and operators. He has been developing and operating MMO, social & mobile games of varying genres since 2006 and has a large depth of experience in what makes online games sustainable & profitable.  He also is well aware of what can kill games and the companies behind them and seeks to educate people how to avoid those mistakes and achieve success. Follow him on twitter: @socialgamesguy


Share Your Thoughts

Top