Hi guys,
Wanted to share a code snippet for logging your project. ( currently used/tested for items that have stage "ref" )
In main.lua add:
stage:addEventListener("logEvent",
function(event)
print(os.date(),"LOG:" , event["log"])
end
)
in any Sprite add:
function sendLog(message)
event = Event.new("logEvent")
event["log"] = message
stage:dispatchEvent(event)
end
and then use like this:
function someFunction()
sendLog("someFunction called")
end
The log will look something like :
Sat Jun 9 21:41:37 2012 LOG: soundButtonHandler
Sat Jun 9 21:41:37 2012 LOG: soundButtonHandler
Sat Jun 9 21:41:38 2012 LOG: howToHandler
Sat Jun 9 21:41:38 2012 LOG: howToClick
Sat Jun 9 21:41:38 2012 LOG: goToStage
Sat Jun 9 21:41:38 2012 LOG: goBackToStage
Sat Jun 9 21:41:39 2012 LOG: startButtonHandler
Sat Jun 9 21:41:39 2012 LOG: startButtonClick
Hope it helps.
Comments
Create an object called logger:
logger = Core.class()
function logger:init(t)
print("logger here")
end
function logger:log(message)
print(os.date(),"LOG:" , message)
end
init in main
logger = logger.new()
and then call from everywhere:
logger:log("goBackToStage")
For who doesn't use a logger class, redefining an empty print function as:
-- variable definition
local logEnabled = true
-- example call
Log:log(logEnabled, 'Test', 'Message')
Likes: ktc
http://wujitouch.com
In the example above you should be able to simply write "if enabled then print(...) end"