Page 1 of 1

[Mod] Chat log [chatlog]

PostPosted: Sun Jun 09, 2013 11:58
by JBR
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!

PostPosted: Sun Jun 09, 2013 14:20
by Mito551
most people here are european. if i'm not wrong. funny pic, lol

PostPosted: Sun Jun 09, 2013 14:27
by Nore
Looks good! However, you have to specify a license (for example, CC0), because public domain is not one.

PostPosted: Sun Jun 09, 2013 16:01
by JBR
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.

PostPosted: Sun Jun 09, 2013 16:02
by JBR
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.

PostPosted: Sun Jun 09, 2013 16:05
by PilzAdam
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.

PostPosted: Sun Jun 09, 2013 16:11
by JBR
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.

PostPosted: Sun Jun 09, 2013 16:13
by PilzAdam
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.

PostPosted: Sun Jun 09, 2013 16:13
by rubenwardy
Is chat not logged in debug.txt?

PostPosted: Sun Jun 09, 2013 16:14
by JBR
rubenwardy wrote:Is chat not logged in debug.txt?

It's not on mine

PostPosted: Sun Jun 09, 2013 16:15
by JBR
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.

PostPosted: Sun Jun 09, 2013 16:16
by JBR
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.

PostPosted: Sun Jun 09, 2013 18:15
by JBR
added dropbox direct download

PostPosted: Mon Jun 10, 2013 09:26
by rubenwardy
JBR wrote:
rubenwardy wrote:Is chat not logged in debug.txt?

It's not on mine


You have to do

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
debug_level = 2


or similar setting in settings.conf

Re:

PostPosted: Tue Dec 23, 2014 13:43
by CraigyDavi
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:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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)

Re: Re:

PostPosted: Tue Dec 23, 2014 14:12
by Hybrid Dog
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:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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

Re: [Mod] Chat log [chatlog]

PostPosted: Tue Dec 23, 2014 18:03
by Linuxdirk
Can we have %Y-%m-%dT%X (or a minetest.conf option) to be ISO compliant? :)

Re: [Mod] Chat log [chatlog]

PostPosted: Tue Dec 23, 2014 19:13
by Krock
How about:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
os.date("%x") -> date
os.date("%x %X") -> date time

Re: [Mod] Chat log [chatlog]

PostPosted: Thu Dec 25, 2014 20:12
by WebWolf
Hi all,
Also instead of the line:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local chatlog = minetest.get_worldpath().."/chatlog.txt"

One could use the following two lines:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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,

Re: [Mod] Chat log [chatlog]

PostPosted: Thu Dec 25, 2014 23:12
by Linuxdirk
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.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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.

Re: [Mod] Chat log [chatlog]

PostPosted: Mon Feb 13, 2017 20:57
by QwertyDragon
I am using Linuxdirk's version:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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?

Re: [Mod] Chat log [chatlog]

PostPosted: Wed Feb 15, 2017 22:35
by Linuxdirk
Can’t reproduce with the version provided by Arch Linux.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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