LoveProfiler is an extremely simple logger and profiler for Löve2D framework. It displays useful information about the current state of a running game. It also can log events at three levels: information, warnings and errors. The output of the profiler is displayed on the Löve2D canvas or in the console (terminal).
Installation is very easy. Just use git clone or copy directory loveprofiler
into your game's directory where file main.lua
is.
git clone https://github.com/dknight/loveprofiler
Example project structure:
love2dproject/
loveprofiler/
main.lua
The most basic usage, create an instance of love.load()
then call start() method inside love.draw()
.
local LoveProfiler = require("loveprofiler")
function love.load()
profiler = LoveProfiler:new()
end
function love.draw()
profiler:start()
end
You can find all possible configuration options with detailed description in defaults.lua
file. You can override any option when you create a new instance.
local LoveProfiler = require("loveprofiler")
function love.load()
profiler = LoveProfiler:new{config = {
driver = "console",
font_size = 17,
draw_x = 400,
color = {0, 0, 1, 1}
}}
end
function love.draw()
profiler:start()
end
At the moment only 2 drivers are supported: canvas and console. If a driver is set to canvas then information is displayed directly on the Löve2D canvas. If console then output will be displayed in the console (system terminal). See defaults.lua
file for more details.
There are 3 levels of messages:
- information;
- warning;
- error.
You can add a log entry like this:
local LoveProfiler = require("loveprofiler")
function love.load()
profiler = LoveProfiler:new()
profiler:addMessage("Your information message", LoveProfiler.LOG_INFO)
profiler:addMessage("Your warning message", LoveProfiler.LOG_WARN)
profiler:addMessage("Your error message", LoveProfiler.LOG_ERROR)
end
By default, logs are also saved in a file loveprofiler.log
. You can change the logging destination by changing the configuration property log_path = "your_path_to_log_file"
, see defaults.lua
. Also if you set log_path = nil
, output won't be saved into file at all.
To completely disable logging set configuration property log_enabled = false
.
You can create as many LoveProfiler instances as you want with different configurations.
local LoveProfiler = require("loveprofiler")
function love.load()
profiler1 = LoveProfiler:new()
profiler2 = LoveProfiler:new{config = {
driver = "console",
font_size = 18,
draw_x = 400,
}}
end
function love.draw()
profiler1:start()
profiler2:start()
end
Found a bug or implemented a new feature? Do not hesitate to make a pull request.
This software is distributed under MIT license, so you are free to use it.