Ent - simple & easy to use logging library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Ent - simple & easy to use logging library

Post by Lafolie »

Hello guys & gals, here is my logging lib 'Ent'. Here's some features straight from the readme:
  • Minimal, simple API
  • Threaded to prevent disk I/O lag spikes
  • Outputs to HTML or plaintext
  • Automatically removes old log files (configurable)
  • Customisable log levels
  • Easy to integrate
And here is the example code:

Code: Select all

ent = require "ent"

function love.load()
	-- create the logfile & writer thread
	ent.init()
end

function love.keypressed(key)
	-- log keypresses from the player
	ent.echo(key)
end

function love.quit()
	-- close the logfile & writer thread
	ent.close()
end
The main caveat to using Ent is by design - only 1 log file can be created per session. This is to emphasise ease of use (no need to be juggling filenames).

Another thing to note is that the output functions are created dynamically from the configured log levels. By default it comes with 7 levels which can be accessed as such:

Code: Select all

ent.echo
ent.info
ent.warn
ent.error
ent.edit
ent.client
ent.server
All ouput functions use the same signature as `string.format` and will perform the formatting. The output will have the timestamp and log level prepended to the input.

Code: Select all

local str = ent.info("Obey %s", "love")
Repo link: https://github.com/Lafolie/ent
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Ent - simple & easy to use logging library

Post by KayleMaster »

Looks great! Probably time to replace my print statements.
Can I request a feature?

Code: Select all

local map_logger = ent.logger("map")
map_logger.info("Loaded map Abyss")

-- Output
[map] Loaded map Abyss

Would be nice to have a built in wrapper so I can differentiate between various systems.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Ent - simple & easy to use logging library

Post by Lafolie »

KayleMaster wrote: Thu Jan 13, 2022 8:59 pm Looks great! Probably time to replace my print statements.
Can I request a feature?
Hey KayleMaster, thanks for your interest. Regarding your question, you can already do this by providing custom log levels. You can pass in a table to override the defaults with the init function. Each log level entry should be a table with 2 strings: the level lable, and a hex colour for HTML output. Ent will generate a function using the key of the table in the log levels table.

For example:

Code: Select all

local ent = require "ent"
local logLevels = 
{
	-- these are the defaults
	echo = {"Echo", "#aaaaaa"},
	info = {"Info", "#2288dd"},
	warn = {"Warning", "#dddd22"},
	error = {"Error!", "#ff44aa"},
	edit = {"Editor", "#88ddbb"},
	client = {"NetClient", "#aaaaaa"},
	server = {"NetServer", "#aaaaaa"},
	-- custom levels
	map = {"Map", "#ff8833"}
}

ent.init {logLevels = logLevels}

ent.map "Chocolate cake" -- will output "[00:00:00:00] (Map) Chocolate cake" in blueish text

--these also work
ent.info "Lemon cake"
ent.error "Bacon cake"
--etc
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Ent - simple & easy to use logging library

Post by KayleMaster »

That will work for me, although I was thinking of in conjuction with log levels. That being said, I think this is the better option anyways. Thanks!
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Ent - simple & easy to use logging library

Post by Lafolie »

KayleMaster wrote: Fri Jan 14, 2022 4:44 pm That will work for me, although I was thinking of in conjuction with log levels. That being said, I think this is the better option anyways. Thanks!
No worries. Thanks for the feedback :)

Do let me know if you have any more suggestions or if you encounter any issues - feel free to file a ticket on github.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests