Make a logging system

Hi
I wana make a logging system that saves the stuff that happens on the server to a mysql db.
Im new att lua so if there is a script that already does this please post it, if it dosnt exist what command should i use to check when props is spawned deleted, when guys gets banned etc.

Here

already searched didnt find anything.
This isnt helping…

Well you could look at this tutorial at gmod wiki: http://wiki.garrysmod.com/?title=LUA:SQLite_Tutorial

that isnt a logging system…
but thanks anyway.
i know how to use sql in lua.
but i want to know how to make a logging system.

Logging is generally better with text files. MySQL databases are designed to save things like cookies and statistics rather than condumps.

For example,

[lua]
local LOG_CURRENT = “mylog.txt”

function WriteToLog( str )
filex.Append( LOG_CURRENT, str … "
" )
end

function ReadLog()
return file.Read( LOG_CURRENT )
end

function ChangeLog( path )
LOG_CURRENT = path
end[/lua]

**[File.Write

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=File.Write)**

thank you but what code should i make to write things from the log to the log file?
right now its just how to write and read the log file and how to make it run on the event.

Log = Log file

There’s not much point is making just a random string of logs and then saving it whenever.

The code above works fine.

huh? this code isnt even logging its just a function to write to a file and read a file…

Writing to a file is the same thing as “logging” an action.

Ok this is what I want the logging system to do…
It should automaticly log when people join, quit, spawn props etc.
This is what I want it to do.

In the appropriate hooks use the logging functions that Entoros kindly provided, for example:

[lua]hook.Add(“PlayerDeath”, “LogDeaths”, function(victim, inflicter, killer)
WriteToLog(victim:Nick()…“was killed by”…killer:Nick())
end)[/lua]

Why not use **[G.ServerLog

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=G.ServerLog)** so it gets inserted into the actual server log ( which I think is what is wanted )?

I had no idea that existed.

i want to make a own logging system so i can load it to my website…
but thanks anyway
-snip-

[editline]03:48PM[/editline]

-snip-


Timer Error: autorun/server/logging.lua:40: attempt to call local 'ply' <a userdata value>

the code for that function is here:


hook.Add("WeaponEquip", "Weapon", function(weapon)

timer.Simple(10, function() 
 
        local ply = weapon:GetOwner()        
        WriteToLog( os.date() .. ": " .. ply():GetName() .. " spawn a " .. weapon:GetClass())
     end)
end)

do anyone know how to solve this problem?

In the WriteToLog you used “ply()”, which is like calling a function. You just want to call a function off of the player object, so you just want to say ply:GetName().

oh thanks.
and i got one more problem
i want the server to dont log the weapons you spawn with and i tried this code:

hook.Add("WeaponEquip", "Weapon", function(weapon)

timer.Simple(10, function() 
 
        local ply = weapon:GetOwner()
        local array = {
                weapon_crowbar,
                weapon_pistol,
                weapon_smg1,
                weapon_frag,
                weapon_physcannon,
                weapon_crossbow,
                weapon_shotgun,
                weapon_357,
                weapon_rpg,
                weapon_ar2,
                gmod_tool,
                gmod_camera,
                weapon_physgun}
        if(weapon:GetClass()!= array) then
        WriteToLog( os.date() .. ": " .. ply:GetName() .. " spawn a " .. weapon:GetClass())
        end
     end)
end)

table.HasValue

Also, weapon():GetClass() returns a string, not a null value.

i fixed this, but thanks anyway.
Admin please lock