Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Corona Advanced Logging
Started by daniel.strmecki Aug 03 2014 08:55 AM

5 replies to this topic
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Enthusiast

  • 71 posts
  • Corona SDK



I would like to present my first public Corona / Lua module. Looking forward to your feedback and suggestions.


Repository: https://github.com/promptcode/CoronaAdvancedLogging




Used for error handling and logging events to console and a set of rolling text log files.

  • Use it instead of print in your Corona project
  • Your messages will be printed in console but also logged in text files
  • Every message in log file contains time, log level and caller trace (module name and line number)
  • A set of rolling text files is used so you can retrace the steps that lead to a bug
  • Runtime errors get logged automatically (including stacktrace)
  • Users get automatically prompt on runtime errors and can report them via email
  • Application administrator receives device / platform info and log files in attachment



build.settings - required for better debugging on device


settings = {
    build = {
          neverStripDebugInfo = true
sample.lua - you can test this is your main function or download sample project from GitHub
local sqlite3 = require("sqlite3");
local log = require("log")
-- Required to use Advanced logging module
local path = system.pathForFile("sample.db", system.DocumentsDirectory)
db = sqlite3.open(path)  
-- This is the simple setup, see properties and defaults
log:set(db, "your_email_adress@gmail.com")
-- Log your events, use log instead of print
log:log("Advanced logging module is now ready")
-- Here we make an intentional error to test error reporting
asd = asd .. "asd"
log properties - customize log module
-- Prefix for log files
log.fileNamePrefix = "log"
-- Directory where to save log files
log.directory = system.DocumentsDirectory
-- Maximum number of log files
log.numberOfRollingFiles = 6
-- Set to true if you want to trace module name and line number on each info message
log.debugCalls = true
-- Maximum depth for caller traceing
log.debugCallDepth = 4
-- Maximum log file size in Bytes
log.maxFileSizeInBytes = 20480
-- Database table name where to save log parameters
log.tableName = "log_params"
-- Set to true if you want an alert to popup on runtime errors
log.alertErrors = true
-- Title for runtime errors alert
log.alertTitle = "Oops, an error occurred"
-- Text for runtime errors alert
log.alertText = "Please report this error to administrator on email:\n\n"
-- 1st button for runtime errors alert label
log.alertButtonReport = "Report on email"
-- 2nd button for runtime errors alert label
log.alertButtonDismiss = "Dismiss"
-- Email adress on which to send error reports
log.alertEmail = ""
-- Erorr report email subject
log.emailSubject = "Error report"
-- Erorr report email text before device / platform into
log.emailPreText = "Hi\n\nI want to report an error in application. " ..
                   "Logs files are attached. Here is my device info: \n"
-- Erorr report email text after device / platform into
log.emailPostText = "\n\n Thank you."
Here is an example of log file contents.
Runtime errors get automaticly logged and user gets prompt to report error to administrator via email.


Administrator receives an email containing device / platform info and log files.






Edited by danstrmecki, 07 August 2014 - 01:16 PM.

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Corona Geek

  • 2,795 posts
  • Corona SDK

Thank you very much for your contribution. This will be a very useful library especially when working with Corona Viewer.

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Enthusiast

  • 71 posts
  • Corona SDK

Your welcome. I have updated the module for better debugging on device (thanks to Perry Clark).


Corona Viewer does not yet support unhandledError listener, but I hope that won't be the case for long.

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Corona Geek

  • 3,137 posts
  • Enterprise

Thanks for sharing this with the community.  I think folks will find this very useful.  I especially like your bug mailer.


Can I add a suggestion?  You can make your log() method take multiple arguments by changing the old log() function name to logi(), and then by doing this:

local log:log( ... )
   local sep = log.sep or " "
   local message = tostring(arg[1])
   for i = 2, #arg do
      message = message .. sep .. tostring(arg[i])
   self:logi(message) -- Call your original logger here

This test,

log.sep = " "
test("Thanks", "for", "the", "advanced", "logger", "it's", string.format("%X", 49153) )

prints something like:


18.08.2014 08:45:15 - INFO - Thanks for the advanced logger it's C001


[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Contributor

  • 197 posts
  • Corona SDK

Wow, this looks wonderful, thanks god Rob announced it in the From the Forum Issue #33.

I'll give it a try, thanks for sharing!

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Enthusiast

  • 71 posts
  • Corona SDK

Thanks for your feedback, I'm glad you folks like my library and hope it helps you with on device debugging.





Your suggestion is noted and included in latest update with only a small change. More here: http://lua-users.org/wiki/TrailingNilParameters


function log:log( ... )
    local message = ""
    local numOfArguments = arg.n --OK
    --local numOfArguments = #arg --NOT OK, because log:log(nil) would not be logged in this case
A separator paramater has been added. Thanks for your suggestion.