Logging mod

Hey guys, I have tryed to make a logging mod and failed terribly, can any of you help with making one. It would be very helpful if you adding comments in it telling me what parts do so I can learn from it.

[lua]function WriteToLog( text )
filex.Append( “log.txt”, text…"
" ) – Write a new line to the end of the log
end

function PrintLog()
print( file.Read( “log.txt” ) ) – Print what’s in the file
end[/lua]

Not really too hard. I don’t know what you’re trying to log, but that’s up to you.

Do you have a list of the hooks they is?

[lua]
require(“mysql”)
local db, error = mysql.connect(“ip”, “username”, “password”, “database”);

local function logsql( ply, text )
local plynick = ply:Nick()

local escaped = mysql.escape(db, plynick .. ": " .. text)
if ply:Alive() then
mysql.query(db, "INSERT INTO logs (id, log, date_entered) VALUES(0, '" .. escaped .. "' , NOW())");
else
mysql.query(db, "INSERT INTO logs (id, log, date_entered) VALUES(0, '" .. "*DEAD* " .. escaped .. "' , NOW())");
end

end

hook.Add(“PlayerSay”, “logsql”, logsql )

local function logsqlconnect( name, ip )
local plynickconnect = name
local connectinfo = mysql.escape(db, “[NOTICE] " … plynickconnect … " joined the server ( " … ip … " )”)
mysql.query(db, “INSERT INTO logs (id, log, date_entered) VALUES(0, '” … connectinfo … “’ , NOW())”);
end
hook.Add(“PlayerConnect”, “logsqlconnect”, logsqlconnect)

local function logsqlinitialspawn( ply )
local plynickinitialspawn = ply:Nick()
local initialspawninfo = mysql.escape(db, “[NOTICE] " … plynickinitialspawn … " has spawned in the server.”)
mysql.query(db, “INSERT INTO logs (id, log, date_entered) VALUES(0, '” … initialspawninfo … “’ , NOW())”);
end
hook.Add(“PlayerInitialSpawn”, “logsqlinitialspawn”, logsqlinitialspawn)
[/lua]

:smug:

[editline]06:12PM[/editline]

http://misc.diamondbuild.info/logs.php