SLA - Simple Logging Addon (File/SQLite/MySQL)

[release]
Need logging for your server but don’t want an admin mod? SLA (Simple Logging Addon) may be what you are looking for!

SLA can log just about anything. By default, it logs the following:
• Player Connect
• Player Initial Spawn
• Player Disconnect
• Player Chat
• Player Death
• Prop Spawn
• Weapon Spawn
• Entity Spawn
• Ragdoll Spawn
• Vehicle Spawn
• NPC Spawn

However, they can easily be modified/removed/added to.

There are three logging methods available - text file, sqlite (sv.db), and MySQL (using gmsv_mysqloo).
By default, only text file is enabled (logging to data/sla_logs/DATE.txt), however, you can enable or disable as many as you want.

To enable/disable/configure logging methods, look at the lua/sla/savetypes/ folder. In there, you will find three files, file.lua, mysql.lua, sqlite.lua.
To enable a method, simply go into the file and change “Enabled = false” to “Enabled = true” at the top.

In mysql.lua you will also find connection information at the top of the file. This is where you configure your host, username, password, port, and database information.
If you would like to use MySQL logging but don’t have a database, you can try db4free.net. However, I haven’t tried this service myself and can’t vouch for the reliability.

This is how logs will appear when using file saving:



[07/06/11 23:34:41] Player rv. connected from 10.10.10.100:27006
[07/06/11 23:34:49] Player rv. (STEAM_0:1:23836998|10.10.10.100:27006) spawned in the server
[07/06/11 23:35:12] Player rv. (STEAM_0:1:23836998|10.10.10.100:27006) spawned prop models/props_borealis/door_wheel001a.mdl
[07/06/11 23:36:29] Player rv. (STEAM_0:1:23836998|10.10.10.100:27006) spawned prop models/props_c17/door01_left.mdl
[07/06/11 23:37:04] Player rv. (STEAM_0:1:23836998|10.10.10.100:27006) spawned prop models/props_c17/door01_left.mdl
[07/06/11 23:37:08] Player rv. (STEAM_0:1:23836998|10.10.10.100:27006) spawned prop models/props_c17/door01_left.mdl
[07/06/11 23:37:08] Player rv. (STEAM_0:1:23836998|10.10.10.100:27006) spawned prop models/props_c17/door01_left.mdl
[07/06/11 23:37:08] Player rv. (STEAM_0:1:23836998|10.10.10.100:27006) spawned prop models/props_c17/door01_left.mdl
[07/06/11 23:37:17] Player rv. (STEAM_0:1:23836998|10.10.10.100:27006) left the server


If using SQLite or MySQL saving, they will appear similar to this:

http://www.seth.im/sla/mysqllogging.png

Hooks can be found in lua/sla/hook.lua. You can modify, add, or remove logging functions in here. To disable a logging function, set “Enabled = false”.
Here is an example of a hook:
[lua]
// Name = Value to pass to second argument of hook.Add
// Enabled = Should this hook run?
// PrintToLog = Whether or not to store the log in file/sqlite/mysql
// PrintToAdmins = Whether or not to print the log to admin’s console
// PrintToRCON = Whether or not to print to RCON/Server console

PlayerConnect = {
Name = ‘SLA:PlayerConnect’,
Enabled = true,
PrintToLog = true,
PrintToAdmins = true,
PrintToRCON = true,
func = function(name, ip)
local msg = string.format(‘Player %s connected from %s’, name, ip);
local fmt = string.format(’[%s] %s’, os.date(’%m/%d/%y %H:%M:%S’), msg);

		if(SLA.Hooks.PlayerConnect.PrintToRCON) then
			print(fmt);
		end
		
		if(SLA.Hooks.PlayerConnect.PrintToAdmins) then
			for k, v in ipairs(player.GetAll()) do
				if(v:IsAdmin()) then
					v:PrintMessage(HUD_PRINTCONSOLE, fmt);
				end
			end
		end
		
		if(SLA.Hooks.PlayerConnect.PrintToLog) then
			SLA.Log(msg);
		end
	end
}

[/lua]

The download is in addon format. You simply unzip and extract to your server’s “addons” folder.
http://www.seth.im/sla/sla.zip

If you encounter any bugs please report them in this topic or via personal message.
[/release]

Wonderful release, thank you :buddy:

Looks promising, I will be using this on my build server.

Awesome addon. Will be using it on my server too.

I have issues connecting to the MySQL database. I have entered the correct information, still it doesnt connect. I have added the IP of the hosting provider in the Remote MySQL. Still doesnt works…

It is possible that your provider doesnt allow external access on your mysql database.

They do allow it. This is what they say:


Do you support remote MySQL connections?
Yes, remote MySQL connections are enabled.
If you are trying to connect to the MySQL server from a remote location (e.g. your computer), use your hosting account IP address as the MySQL hostname. Your server IP address can by found on the left hand column when you login to cPanel. Do not forget to add your computer IP address to the 'cPanel' -> 'Remote MySQL' section.

I’ve added the IP to from my SERVER hosting provider in the Remote MySQL section.

[editline]2nd December 2011[/editline]

I just registered a paid domain and hosting. To be honest, about 5 hours ago. Could it be that? Cuz my little PHP script doesn’t work and the domain isn’t up yet. I’ve trained some on the free hosting before I bought this.

<?PHP

//connect to the server
$connect = mysql_connect("HOST","USERNAME","PASSWORD", "PORT");

//connect to the database
mysql_select_db("somedb_forums");

//query the database
$query = mysql_query("SELECT * FROM test");

//fetch the results

		WHILE($rows = mysql_fetch_array($query)):
		
			$icons_url = $rows['icons_url'];
			
		echo "$icons_url";
			
		endwhile;

?>

This was just a small PHP script I made. I’m still learning. This will show some information in a pre-made forum that I had when I used a free hosting and imported that DB to this new paid one.

Sometimes box’s have more than one IP then the one your server is binded on:
use this:


function fuck(contents , size)
	Msg(contents.."
")
end
http.Get("http://whothefuckami.com", "", fuck) 

I’ve now fixed everything up, it’s connecting and sends data, although, this code leaks info. Since the code will have to connect each time logging to the Database, and it’s an interval between connection and connected, it would leak data. Durning the time which the code connects to the DB, everything that happens between connecting and connected will get lost.

Any clues how to fix this?