simple log library crashes love without notice

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
uiblob
Prole
Posts: 8
Joined: Sun Jun 10, 2018 8:06 am

simple log library crashes love without notice

Post by uiblob »

Hi,

just getting started with love, but I have an error I don't know how to debug. :|

The game simply crashes without any errors. How can I debug this? What am I doing wrong? :?

Greetings
Karl

Here is the code of my lib
dlog.love
(895 Bytes) Downloaded 149 times
debuglog.lua

Code: Select all

if ddebuglog then
   love.filesystem.write ("log", "Started")
end

local dlog = {}

local function logwrite (sign, message)
   if ddebuglog then
      local timestamp = os.date("%F-%R:%S")
      local msgstring = string.format ("(%s) %s %s", sign, timestamp, message)

      love.filesystem.append("log", msgstring)
   end
end

function dlog.error (message)
   logwrite("E", message)
end

function dlog.info (message)
   logwrite("I", message)
end

dlog.info("Log init done.")

return dlog
main.lua

Code: Select all

love.filesystem.createDirectory(love.filesystem.getSaveDirectory())

ddebuglog = true

local dlog = require "debuglog"

dlog.info("hi")

function love.draw()
	love.graphics.print("hi")
end
conf.lua

Code: Select all

function love.conf(t)
   t.identity = logtest          -- The name of the save directory (string)
   t.console = true
end
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: simple log library crashes love without notice

Post by MrFariator »

Code: Select all

local timestamp = os.date("%F-%R:%S")
This particular line seems to be at fault; I checked the lua docs for the usage of os.date and it did not list %F or %R as legible arguments, which for a reason or another results in lua runtime to instantly hang up. I changed the line to something like the following, and there was no crashing.

Code: Select all

local timestamp = os.date("%c")
On another note, you may want to handle the save directory differently, because as it stands the log file will be written in to a folder titled "conf" under %appdata%\LOVE, as opposed to "dlog" or something along those lines.
uiblob
Prole
Posts: 8
Joined: Sun Jun 10, 2018 8:06 am

Re: simple log library crashes love without notice

Post by uiblob »

MrFariator wrote: Sun Jun 10, 2018 10:29 am

Code: Select all

local timestamp = os.date("%F-%R:%S")
This particular line seems to be at fault; I checked the lua docs for the usage of os.date and it did not list %F or %R as legible arguments, which for a reason or another results in lua runtime to instantly hang up. I changed the line to something like the following, and there was no crashing.

Code: Select all

local timestamp = os.date("%c")
Thanks. I was somehow mixing it up with http://www.cplusplus.com/reference/ctime/strftime/
On another note, you may want to handle the save directory differently, because as it stands the log file will be written in to a folder titled "conf" under %appdata%\LOVE, as opposed to "dlog" or something along those lines.

Another thanks, I forgot the "" in the conf.lua there is no warning if the identity is not a string.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests