SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 19/03/2016, 06:28 PM   #1
maddinat0r
Gangsta
 
maddinat0r's Avatar
 
Join Date: Jun 2010
Location: Germany
Posts: 882
Reputation: 428
Default Log plugin

Log plugin v0.3

This is a simple logging plugin, utilizing the log-core utility also used by the MySQL and Discord Connector plugin.

What does this plugin do?
As the name implies, it provides natives to easily log stuff. You can create multiple loggers, each with their own name, and log whatever you want into them.
Each logger represents a log file. If you create a logger with "system" as its name, the log core will create a file named "system.log" in the "log" folder (also created by the log core). You can also specify a name like "system/player/money" and the log core will create a folder "player" within an also created folder "system" and place a "money.log" file into it.

How do I quickly find in which file happened any errors or warnings?
The log core automatically creates two files in the "log" directory: "warnings.log" and "errors.log". It logs all errors and warnings logged by any other logger into these files. Of course it also writes down the logger name, so you can quickly see which system has reported that error/warning.

I have a really huge gamemode, split up into many files, and always searching for the correct log lines in my code sounds very troublesome. Is there any way to quickly find out where in my code the log message was sent from?
Yes, you just have to compile your gamemode with debug informations (PAWN compile flag "-d3"). The log plugin will automatically detect this and append line number and file name to every log message.

I'm worried about performance. How fast is this plugin?
The log core is completely threaded, thus any writes to the actual file won't halt the PAWN thread. There are also crash handlers installed in case the server crashes, so that the plugin always finishes writing all queued log messages before actually crashing.

So how do I actually use this in my gamemode?
Code:
#include <a_samp>
#include <log-plugin>


new
	Logger:mainlog,
	Logger:playerlog,
	Logger:playermoneylog,
	Logger:systemlog;

public OnGameModeInit()
{
	mainlog = CreateLog("main");
	playerlog = CreateLog("player/main");
	playermoneylog = CreateLog("player/money");
	systemlog = CreateLog("system", DEBUG | INFO | WARNING | ERROR);
	
	Log(mainlog, INFO, "created all loggers");
	Log(playerlog, WARNING, "playerid %d is moving too %s", 1234, "fast");
	Log(playermoneylog, ERROR, "invalid amount %f", 3.14532);
	Log(systemlog, DEBUG, "update took %d seconds", 4321);
	return 1;
}


public OnGameModeExit()
{
	DestroyLog(mainlog);
	DestroyLog(playerlog);
	DestroyLog(playermoneylog);
	DestroyLog(systemlog);
	return 1;
}
How many log levels are there?
Debug, info, warning and error.

I don't like the way the plugin prints the time into the log. How can I change this?
The log core uses the "logtimeformat" property from the "server.cfg". Change that property and the log core will format time and date according to the specified value.

Is there anything else I need to know?
You can't use a logger name like "plugins/myplugin". The "plugins/" name is reserved for plugins. As mentioned before, the MySQL plugin, starting at R40, will use the log core and log everything into that folder. Any other plugin developer can also implement the log core into their plugins to log anything conveniently and fast, PM me or ask in this thread if there are specific questions regarding this.
Additionally, you can't use "log-core" as a logger name. This log file is reserved for the log-core itself. In case of a crash, the log-core will log that crash into this file.


I guess that's it. Oh, wait, the links:
Download: https://github.com/maddinat0r/samp-log/releases
Source: https://github.com/maddinat0r/samp-log

I'll appreciate any feedback and constructive criticism.

Last edited by maddinat0r; 24/12/2016 at 10:59 AM. Reason: v0.3
maddinat0r is offline   Reply With Quote
Old 19/03/2016, 07:02 PM   #2
Max_Andolini
Huge Clucker
 
Max_Andolini's Avatar
 
Join Date: Oct 2013
Posts: 273
Reputation: 31
Default Re: Log plugin

You are amazing maddinat0r
Max_Andolini is offline   Reply With Quote
Old 19/03/2016, 07:36 PM   #3
Dragony92
Gangsta
 
Dragony92's Avatar
 
Join Date: Feb 2011
Location: Belgrade, Serbia
Posts: 571
Reputation: 57
Default Re: Log plugin

Again, very nice plugin, well done!
__________________
Dragony92 is offline   Reply With Quote
Old 06/05/2016, 02:27 PM   #4
DarkSlyder
Huge Clucker
 
DarkSlyder's Avatar
 
Join Date: Mar 2010
Location: Italy
Posts: 222
Reputation: 35
Default Re: Log plugin

I've been using this plugin since its release on a 50+ players server without any trouble, I love the threaded logging feature.
Anyway I've just noticed that the timestamp is always printed as "]".
That's my logtimeformat in server.cfg and and example Log function call, I'm on Debian 8 x64:
Code:
//Printing a log somewhere in my mode
Log(adminlog, INFO, string);

//server.cfg
logtimeformat [%d/%m/%Y %H:%M:%S]

//Output
] [INFO] *** Game Mod <someone>: <something he said> (sfrp_parts/Admin/sfrp_class.inc:258)
Also, is there a way to disable file name and line number beside not compiling with -d3?
DarkSlyder is offline   Reply With Quote
Old 07/05/2016, 12:01 PM   #5
maddinat0r
Gangsta
 
maddinat0r's Avatar
 
Join Date: Jun 2010
Location: Germany
Posts: 882
Reputation: 428
Default Re: Log plugin

Thanks for the feedback!

I couldn't reproduce your issue with the specified logtimeformat value. Can you write a small script to reproduce this?
And no, there is no way to disable appending debug information when they're available. Is there a reason you don't want them in your log messages even though you compile with full debug information?
maddinat0r is offline   Reply With Quote
Old 07/05/2016, 12:19 PM   #6
Mark_Samp
Huge Clucker
 
Mark_Samp's Avatar
 
Join Date: Oct 2012
Posts: 350
Reputation: 30
Default Re: Log plugin

Unique , Just amazing!
__________________
Quote:
Originally Posted by Tvietnam View Post
Hello all members in forum.sa-mp.com .
I would like to introduce myself tiny in.
I was the first person in Vietnam . sociable fun like especially like looking inquisitive learning . I posted this article so that you can only create one people to recognize me for Samp . Hope you can only thanks very much
because I am the one who should not fluent in Vietnam of your country , so I have to use the google translation tool . What if there is no proper word or not , please ignore
Mark_Samp is offline   Reply With Quote
Old 25/05/2016, 04:21 PM   #7
blackeagle1122
Big Clucker
 
Join Date: Aug 2013
Posts: 60
Reputation: 3
Default Re: Log plugin

Quote:
Originally Posted by DarkSlyder View Post
I've been using this plugin since its release on a 50+ players server without any trouble, I love the threaded logging feature.
Anyway I've just noticed that the timestamp is always printed as "]".
That's my logtimeformat in server.cfg and and example Log function call, I'm on Debian 8 x64:
Code:
//Printing a log somewhere in my mode
Log(adminlog, INFO, string);

//server.cfg
logtimeformat [%d/%m/%Y %H:%M:%S]

//Output
] [INFO] *** Game Mod <someone>: <something he said> (sfrp_parts/Admin/sfrp_class.inc:258)
Also, is there a way to disable file name and line number beside not compiling with -d3?
I just commented the debug info section and recompiled it.

https://www.solidfiles.com/v/43m7vdndMVreM

It's for windows, if you want I can compile it for linux too.
blackeagle1122 is offline   Reply With Quote
Old 06/07/2016, 11:41 AM   #8
Kenshin869
Little Clucker
 
Join Date: Jul 2010
Posts: 2
Reputation: 1
Default Respuesta: Log plugin

Hello, I jump a Warning when compiling this plugin to include mysql, I place before or after the mysql include?

Code:
include\a_mysql.inc(30) : warning 201: redefinition of constant/macro (symbol "E_LOGLEVEL")
Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase

Header size:          36616 bytes
Code size:          9170208 bytes
Data size:         70209668 bytes
Stack/heap size:      16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements:79432876 bytes

1 Warning.
Kenshin869 is offline   Reply With Quote
Old 06/07/2016, 11:49 AM   #9
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,984
Reputation: 418
Default Re: Log plugin

again a great work
__________________

SyS is offline   Reply With Quote
Old 23/07/2016, 03:39 PM   #10
PrO.GameR
Gangsta
 
PrO.GameR's Avatar
 
Join Date: Oct 2012
Posts: 738
Reputation: 121
Default Re: Log plugin

Great plugin, now I won't be bothered working on something similar and way worse just to have it "working".
Quote:
Originally Posted by maddinat0r View Post
Thanks for the feedback!

I couldn't reproduce your issue with the specified logtimeformat value. Can you write a small script to reproduce this?
And no, there is no way to disable appending debug information when they're available. Is there a reason you don't want them in your log messages even though you compile with full debug information?
Yes there are simple reasons, like using this for logging player commands or just their plain text, we don't need to know where we used logger for a Player_Name: Hello. (simple chat logging.)
However we might need the -d3 for the crashdetect plugin.

I suggest adding a new parameter to CreateLog function.
PHP Code:
    CreateLog(address[], logline=1); 
It would then check both -d3 option and createlog's parameter to see if we need the line and file name or not.
__________________
Blueberry Prison Roleplay will be back soon!
Follow the forums for more information about opening day.

Forums
PrO.GameR is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Centos7 - Streamer plugin and crashdetect plugin Su37Erich Server Support 3 12/08/2016 12:18 AM
[MySQL] From StickenKid's plugin to BlueG's plugin jessejanssen Scripting Help 2 15/06/2014 01:20 AM
Very good plugin suggestion (for scripters) and easy to make for the Plugin Developers! Xentiarox Plugin Development 5 29/07/2012 10:48 PM
[Question] Plugin Load Failed : Plugin Does not conform to architecture. Gamer_Z Plugin Development 2 09/06/2011 06:42 AM
mysql plugin. loading plugin failed ikkentim Help Archive 2 10/02/2011 02:32 PM


All times are GMT. The time now is 10:59 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.