[Mod] Chat log [chatlog]

User avatar
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

[Mod] Chat log [chatlog]

by JBR » Post

The name says it all. Creates a chatlog.txt file in the world directory.

I don't know if this already exists but I couldn't find one so I decided to make one.

Also there is a monthfirst variable inside the init.lua which does what it says(if true the date for Feb 1st would be 2/1/13 if false it would be(1/2/13) and by default I made it true because i'm guessing most people here are American?

The chat log looks something like this(note: the monthfirst is set to false in this picture):
Image

License: CC0
Download:
4Shared(zip)
Dropbox(zip direct download)

Enjoy!
Last edited by JBR on Sun Jun 09, 2013 18:15, edited 1 time in total.

User avatar
Mito551
Member
Posts: 1271
Joined: Sat Jun 16, 2012 15:03

by Mito551 » Post

most people here are european. if i'm not wrong. funny pic, lol

Nore
Developer
Posts: 501
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Post

Looks good! However, you have to specify a license (for example, CC0), because public domain is not one.

User avatar
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

Nore wrote:Looks good! However, you have to specify a license (for example, CC0), because public domain is not one.
Well I don't like the minetest's version of public domain because it has swearing in it and I think public domain is perfectly valid.

User avatar
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

Mito551 wrote:most people here are european. if i'm not wrong. funny pic, lol
So do you think I should change the default value to false? And the pic is meant to show how you can use it to see whether people are lying or whatever but yeah it is pretty funny.
Last edited by JBR on Sun Jun 09, 2013 16:04, edited 1 time in total.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

JBR wrote:
Nore wrote:Looks good! However, you have to specify a license (for example, CC0), because public domain is not one.
Well I don't like the minetest's version of public domain because it has swearing in it and I think public domain is perfectly valid.
First of all, WTFPL is not "minetest's version of public domain", its a valid and wiedly used license.
Second: public domain is not a license in some countries, thus its not accepted in this forum.
Third: Choose CC0 if you dont like the "swearing" in WTFPL.

User avatar
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

PilzAdam wrote:
JBR wrote:
Nore wrote:Looks good! However, you have to specify a license (for example, CC0), because public domain is not one.
Well I don't like the minetest's version of public domain because it has swearing in it and I think public domain is perfectly valid.
First of all, WTFPL is not "minetest's version of public domain", its a valid and wiedly used license.
Second: public domain is not a license in some countries, thus its not accepted in this forum.
Third: Choose CC0 if you dont like the "swearing" in WTFPL.
Ok, though what does CC0 stand for?

Edit: Sorry if I came across a bit uptight when I said " public domain is perfectly valid" I didn't mean to be and TBH I don't care much about the license for this.
Last edited by JBR on Sun Jun 09, 2013 16:14, edited 1 time in total.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

JBR wrote:
PilzAdam wrote:
JBR wrote:
Well I don't like the minetest's version of public domain because it has swearing in it and I think public domain is perfectly valid.
First of all, WTFPL is not "minetest's version of public domain", its a valid and wiedly used license.
Second: public domain is not a license in some countries, thus its not accepted in this forum.
Third: Choose CC0 if you dont like the "swearing" in WTFPL.
Ok, though what does CC0 stand for?
http://creativecommons.org/publicdomain/zero/1.0/ 0.5 seconds search in the internet.

User avatar
rubenwardy
Moderator
Posts: 6371
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: United Kingdom
Contact:

by rubenwardy » Post

Is chat not logged in debug.txt?

User avatar
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

rubenwardy wrote:Is chat not logged in debug.txt?
It's not on mine

User avatar
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

Hybrid Dog wrote:You could use
0130608124237 Noob message
instead of
(09/06/13 12:42:37) [Noob]: message
to make it more simple.

That seems harder to read to me.

User avatar
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

PilzAdam wrote:
JBR wrote:
PilzAdam wrote: First of all, WTFPL is not "minetest's version of public domain", its a valid and wiedly used license.
Second: public domain is not a license in some countries, thus its not accepted in this forum.
Third: Choose CC0 if you dont like the "swearing" in WTFPL.
Ok, though what does CC0 stand for?
http://creativecommons.org/publicdomain/zero/1.0/ 0.5 seconds search in the internet.
Yeah your right sorry for being so lazy. Changing now.

User avatar
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

added dropbox direct download

User avatar
rubenwardy
Moderator
Posts: 6371
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: United Kingdom
Contact:

by rubenwardy » Post

JBR wrote:
rubenwardy wrote:Is chat not logged in debug.txt?
It's not on mine
You have to do

Code: Select all

debug_level = 2
or similar setting in settings.conf

User avatar
CraigyDavi
Member
Posts: 582
Joined: Sat Aug 10, 2013 13:08
GitHub: davisonio
IRC: davisonio
In-game: CraigyDavi
Location: Hampshire, UK
Contact:

Re:

by CraigyDavi » Post

A crash occurs when someone uses the percentage sign (%) in the chat.
For anyone wanting to use this mod, you could use this code instead to fix it:

Code: Select all

local chatlog = minetest.get_worldpath().."/chatlog.txt"

function playerspeak(name,msg)
	f = io.open(chatlog, "a")
	f:write(os.date("(%m/%d/%y %X) [")..name.."]: "..msg.."\n")
	f:close()
end

minetest.register_on_chat_message(playerspeak)

User avatar
Hybrid Dog
Member
Posts: 2774
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Re:

by Hybrid Dog » Post

CraigyDavi wrote:A crash occurs when someone uses the percentage sign (%) in the chat.
For anyone wanting to use this mod, you could use this code instead to fix it:

Code: Select all

local chatlog = minetest.get_worldpath().."/chatlog.txt"

function playerspeak(name,msg)
	f = io.open(chatlog, "a")
	f:write(os.date("(%m/%d/%y %X) [")..name.."]: "..msg.."\n")
	f:close()
end

minetest.register_on_chat_message(playerspeak)
thanks

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Linuxdirk
Member
Posts: 2713
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Chat log [chatlog]

by Linuxdirk » Post

Can we have %Y-%m-%dT%X (or a minetest.conf option) to be ISO compliant? :)

User avatar
Krock
Developer
Posts: 4577
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: [Mod] Chat log [chatlog]

by Krock » Post

How about:

Code: Select all

os.date("%x") -> date
os.date("%x %X") -> date time
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
WebWolf
Member
Posts: 15
Joined: Thu Jun 19, 2014 05:00

Re: [Mod] Chat log [chatlog]

by WebWolf » Post

Hi all,
Also instead of the line:

Code: Select all

local chatlog = minetest.get_worldpath().."/chatlog.txt"
One could use the following two lines:

Code: Select all

local chatdate = (os.date("%Y%m%d")) --chatdate will be, for example, 20150127.txt -->> YYYY MM DD (year month day)
local chatlog = minetest.get_worldpath().."/chatlog/"..chatdate..".txt"
This way, the chat will be saved in daily files (several separated smaller files, one file for each day, in an ordinal and easy to find way), instead of a very big file.

Note: The files will be inside a new directory (a subdirectory) named "chatlog", inside the "worlds/nameOfTheMap" directory.
You need to add some code to create the "chatlog" subdirectory for the first time (before starting the server), or you create it manually (otherwise there will be an error).

Well, just an idea, and trying to share it. :)
Regards,

User avatar
Linuxdirk
Member
Posts: 2713
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Chat log [chatlog]

by Linuxdirk » Post

Since this mod is CC0 and I like the idea of a chat logfile I created my own version of this mod basing on the same idea. I release my version also under CC0.

Code: Select all

-- Helper function for loading optional values
local function getValid(value, default)
    v = minetest.setting_get(value)
    return (v == nil and default or v)
end

-- Default values
local defaultFile = 'chatlog.%Y-%m-%d.log'
local defaultDate = '%X'
local defaultLine = '[%date%] <%name%> %message%\n'

-- Read values from minetest.conf or set default values
chatlogFilename = getValid('chatlog_logfile_name', defaultFile)
chatlogDateString = getValid('chatlog_date_string', defaultDate)
chatlogLineFormat = getValid('chatlog_line_format', defaultLine)

function chatlogWriteLine(name, message)
    local logfileName = os.date(chatlogFilename)
    local line = chatlogLineFormat
    line = line:gsub('%%date%%', os.date(chatlogDateString))
    line = line:gsub('%%name%%', name)
    line = line:gsub('%%message%%', message)
    f = io.open(minetest.get_worldpath()..'/'..logfileName, 'a')
    f:write(line)
    f:close()
end

minetest.register_on_chat_message(chatlogWriteLine)
A default chatlog line is [%date%] <%name%> %message% … where %date%, %name% and %message% get replaced with the actual date, name and message of the chat line being processed. The default file name is chatlog.%Y-%m-%d.log within the world directory.

Since Lua does not have a function to create folders without loading additional modules (which is insecure because the modules in question might not be installed) or system calls (which are not portable between different operating systems) it is not possible to create sub-directories for log files (except you create them manually beforehand).

Changing the default variables is possible in two locations the first location is in init.lua itself in the section “Default values” but that is not desirable (because one should always separate code and configuration). The second and better solution is to define them in your server’s configuration file or the minetest.conf file.

chatlog_logfile_name allows changing the logfile’s file name. You can use the known date variables here (But as described before: no sub-directories except you create them manually). With chatlog_date_string you describe how the date should be represented in the single chatlog entries. And chatlog_line_format defines the actual chatlog lines.

For chatlog_line_format three additional variables are available: %date% gets replaced by the date defined via chatlog_date_string or its default value, %name% gets replaced with the name of the user sending the chat message and %message% gets replaced with the message itself. Other variables are not being replaced.

User avatar
QwertyDragon
Member
Posts: 20
Joined: Sat Dec 24, 2016 15:37
Contact:

Re: [Mod] Chat log [chatlog]

by QwertyDragon » Post

I am using Linuxdirk's version:

Code: Select all

    -- Helper function for loading optional values
    local function getValid(value, default)
        v = minetest.setting_get(value)
        return (v == nil and default or v)
    end

    -- Default values
    local defaultFile = 'chatlog.%Y-%m-%d.log'
    local defaultDate = '%X'
    local defaultLine = '[%date%] <%name%> %message%\n'

    -- Read values from minetest.conf or set default values
    chatlogFilename = getValid('chatlog_logfile_name', defaultFile)
    chatlogDateString = getValid('chatlog_date_string', defaultDate)
    chatlogLineFormat = getValid('chatlog_line_format', defaultLine)

    function chatlogWriteLine(name, message)
        local logfileName = os.date(chatlogFilename)
        local line = chatlogLineFormat
        line = line:gsub('%%date%%', os.date(chatlogDateString))
        line = line:gsub('%%name%%', name)
        line = line:gsub('%%message%%', message)
        f = io.open(minetest.get_worldpath()..'/'..logfileName, 'a')
        f:write(line)
        f:close()
    end

    minetest.register_on_chat_message(chatlogWriteLine)
Minetest 0.4.15 self compiled run-in-place on Ubuntu 14.04
And had a server crash with this error:

Code: Select all

2017-02-13 02:09:42: ERROR[Main]: ServerError: Lua: Runtime error from mod 'chatlog' in callback on_chat_message(): .../STABLE/minetest/bin/../mods/chatlog/init.lua:24: invalid capture index
2017-02-13 02:09:42: ERROR[Main]: stack traceback:
2017-02-13 02:09:42: ERROR[Main]: 	[C]: in function 'gsub'
2017-02-13 02:09:42: ERROR[Main]: 	/STABLE/minetest/bin/../mods/chatlog/init.lua:24: in function <.../STABLE/minetest/bin/../mods/chatlog/init.lua:19>
2017-02-13 02:09:42: ERROR[Main]: 	.../STABLE/minetest/bin/../builtin/game/register.lua:412: in function <.../STABLE/minetest/bin/../builtin/game/register.lua:392>
I do not understand what the error is really pointing to.
Tried to reproduce by typing "%" and every other character in chat, but crash does not reproduce for me. So it does not seem like it happens by user typing % or anything. I like this mod and would like to keep using it, unless there is a better option.

Anyone have any suggestions?
My GitLab, and Obior pages, and YouTube as QuixoticalPig, and Twitter as vuvvobUd. irc as QwertyDragon

User avatar
Linuxdirk
Member
Posts: 2713
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Chat log [chatlog]

by Linuxdirk » Post

Can’t reproduce with the version provided by Arch Linux.

Code: Select all

$ minetest --version
Minetest 0.4.15 (Linux)
Using Irrlicht 1.8.4
Build info: VER=0.4.15 BUILD_TYPE=Release RUN_IN_PLACE=0 USE_GETTEXT=1 USE_SOUND=1 USE_CURL=1 USE_FREETYPE=1 USE_LUAJIT=1 STATIC_SHAREDIR="/usr/share/minetest"

$ lua5.2 -v
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio

$ luajit -v
LuaJIT 2.0.4 -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/

$ uname -rms
Linux 4.9.6-1-ARCH x86_64

iZacZip
Member
Posts: 48
Joined: Sat Dec 05, 2015 10:37

Re: [Mod] Chat log [chatlog]

by iZacZip » Post

This mod works great. One thing though, please add the players joining and leaving in the logs. Thanks.
Ignore my old posts.

User avatar
AntumDeluge
Member
Posts: 167
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge
Contact:

Re: [Mod] Chat log [chatlog]

by AntumDeluge » Post

Created GitHub repo for this.

User avatar
Codesound
Member
Posts: 324
Joined: Thu Jun 09, 2016 14:56

Re: [Mod] Chat log [chatlog]

by Codesound » Post

Hi,

This mod is very USEFUL!!!

Thanks...

I have one question: is possible to add the ip of the players like: <IP> <USER> <TIME-DATE> <message> ?

Thanks again for all...

R

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests