The Gogger - Advanced log system [BETA] -
Gangs_Rocks - 05.09.2012
The Gogger
Advanced log creating and saving
by Gangs a.k.a CreativityLacker
Functions:
pawn Код:
forward CreateLog(logname[]);
forward WriteInLog(logname[], string[]);
Code
pawn Код:
/*
The Gogger - Advanced log creating, writing and saving
by Gangs a.k.a CreativityLacker
Don't remove credits from here
This is the BETA version
Please report any bugs at the topc
*/
#include <file>
#include <a_samp>
forward CreateLog(logname[]);
forward WriteInLog(logname[], string[]);
public CreateLog(logname[])
{
new date[3];
getdate(date[0], date[1], date[2]);
new string[120];
format(string, sizeof(string), "Logs/%s.txt", logname); // Change this to the location you want your logs at
new File:log = fopen(string, io_append);
format(string, sizeof(string), "[%02d-%02d-%04d] Started logging in LOG '%s' ", date[2], date[1], date[0], logname);
fwrite(log, string);
fclose(log);
format(string, sizeof(string), "\r\n[%02d-%02d-%04d] Started logging in LOG '%s'", date[2], date[1], date[0], logname);
printf(string);
return 1;
}
public WriteInLog(logname[], string[])
{
new location[120];
format(location, sizeof(location),"Logs/%s.txt", logname); // Change this to the location you want your logs at
if(fexist(location))
{
new File:log = fopen(location, io_append);
fwrite(log, string);
fclose(log);
}
else return printf("[LOG ERROR]A log wasn't found!");
return 1;
}
Test script :
pawn Код:
#include <a_samp>
#include <Gogger>
main()
{
print("\n----------------------------------");
print(" Testing Log creator");
print("----------------------------------\n");
}
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
CreateLog("TestLog");
return 1;
}
public OnPlayerConnect(playerid)
{
new name[24];
GetPlayerName(playerid, name, sizeof(name));
new string[40];
format(string, sizeof(string), "\r\n%s connected to the server", name);
WriteInLog("TestLog", string);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new name[24];
GetPlayerName(playerid, name, sizeof(name));
new string[40];
format(string, sizeof(string), "\r\n%s disconnected from the server", name);
WriteInLog("TestLog", string);
printf(string);
return 1;
}
Output results after this code:
Console:
Quote:
[16:00:45] Number of vehicle models: 0
[16:01:09] Incoming connection: 127.0.0.1:63878
[16:01:09] [join] Futre has joined the server (0:127.0.0.1)
[16:01:14]
Futre disconnected from the server
[16:01:14] [part] Futre has left the server (0:1)
|
File (scriptfiles/Logs/TestLog.txt):
Quote:
[05-09-2012] Started logging in LOG 'TestLog'
Futre connected to the server
Futre disconnected from the server
|
Please report any bugs, I'll try to fix 'em ASAP
Re: The Gogger - Advanced log system [BETA] -
jueix - 05.09.2012
Quote:
Originally Posted by Gangs_Rocks
The Gogger
Advanced log creating and saving
by Gangs a.k.a CreativityLacker
Functions:
pawn Код:
forward CreateLog(logname[]); forward WriteInLog(logname[], string[]);
Code
pawn Код:
/* The Gogger - Advanced log creating, writing and saving by Gangs a.k.a CreativityLacker Don't remove credits from here This is the BETA version Please report any bugs at the topc */
#include <file> #include <a_samp>
forward CreateLog(logname[]); forward WriteInLog(logname[], string[]);
public CreateLog(logname[]) { new date[3]; getdate(date[0], date[1], date[2]); new string[120]; format(string, sizeof(string), "Logs/%s.txt", logname); // Change this to the location you want your logs at new File:log = fopen(string, io_append); format(string, sizeof(string), "[%02d-%02d-%04d] Started logging in LOG '%s' ", date[2], date[1], date[0], logname); fwrite(log, string); fclose(log); format(string, sizeof(string), "\r\n[%02d-%02d-%04d] Started logging in LOG '%s'", date[2], date[1], date[0], logname); printf(string); return 1; }
public WriteInLog(logname[], string[]) { new location[120]; format(location, sizeof(location),"Logs/%s.txt", logname); // Change this to the location you want your logs at if(fexist(location)) { new File:log = fopen(location, io_append); fwrite(log, string); fclose(log); } else return printf("[LOG ERROR]A log wasn't found!"); return 1; }
Test script :
pawn Код:
#include <a_samp> #include <Gogger>
main() { print("\n----------------------------------"); print(" Testing Log creator"); print("----------------------------------\n"); } public OnGameModeInit() { // Don't use these lines if it's a filterscript SetGameModeText("Blank Script"); AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); CreateLog("TestLog"); return 1; } public OnPlayerConnect(playerid) { new name[24]; GetPlayerName(playerid, name, sizeof(name)); new string[40]; format(string, sizeof(string), "\r\n%s connected to the server", name); WriteInLog("TestLog", string); return 1; }
public OnPlayerDisconnect(playerid, reason) { new name[24]; GetPlayerName(playerid, name, sizeof(name)); new string[40]; format(string, sizeof(string), "\r\n%s disconnected from the server", name); WriteInLog("TestLog", string); printf(string); return 1; }
Output results after this code:
Console:
File (scriptfiles/Logs/TestLog.txt):
Please report any bugs, I'll try to fix 'em ASAP
|
Pretty cool, I will use it to make logs of if a player hacks a gun or dosn't buy one from the shop it will write it in the log.
Re: The Gogger - Advanced log system [BETA] -
Biesmen - 05.09.2012
A log usually prints the exact time the log function has been executed. You could try to add this
Re: The Gogger - Advanced log system [BETA] -
Gangs_Rocks - 05.09.2012
Quote:
Originally Posted by Biesmen
A log usually prints the exact time the log function has been executed. You could try to add this
|
Added. It'll be released in V0.1, I'll release the new version once I've fixed some more shit and added some more shit.
Re: The Gogger - Advanced log system [BETA] - Jarnu - 05.09.2012
uh.. pretty great work brotha repped ^-^
Re: The Gogger - Advanced log system [BETA] -
Kaperstone - 05.09.2012
ammm... intersting,something unqiue.
thanks for the share.
Re: The Gogger - Advanced log system [BETA] -
Shadow_ - 05.09.2012
This is pretty simple stuff, but its good i guess.
You could make it better by using a more efficient storing method ( maybe SQL? )
Also within the 'WriteInLog' callback you have used printf but have not put any string/integer ect. so just use print lol.
Its far from unique or advanced. ^^ just saying.
Re: The Gogger - Advanced log system [BETA] -
Nanory - 05.09.2012
Really cool, but I think that WriteInLog would work fater if you use an identification number instead of a name
Re: The Gogger - Advanced log system [BETA] -
Gangs_Rocks - 05.09.2012
Quote:
Originally Posted by Shadow_
This is pretty simple stuff, but its good i guess.
You could make it better by using a more efficient storing method ( maybe SQL? )
Also within the 'WriteInLog' callback you have used printf but have not put any string/integer ect. so just use print lol.
Its far from unique or advanced. ^^ just saying.
|
1. No other includes like this exist (None that I know of)
2. It's not meant to be very advanced. People still prefer .txt files for logs instead of MySQL (+ If you're so professional, You can convert this code in a minute to MySQL yourself)
3. Okay, I didn't know the difference between printf and print, sorry, my bad
4. Unique or advanced = It is. At average, You require about 6-8 lines of code to write a string in the log.
what i mean is
pawn Код:
new File:log = fopen("Logs/Log.txt", io_append);
new string[120];
new name[24];
GetPlayerName(playerid, name, sizeof(name) );
format(string, sizeof(string), "%s connected to the server", name);
fwrite(log, string);
Can be converted to
pawn Код:
new string[120];
new name[24];
GetPlayerName(playerid, name, sizeof(name) );
format(string, sizeof(string), "%s connected to the server", name);
WriteInLog("Logs/Log.txt", string);
+ You can suggest whatever you want, EXCEPT converting to a more efficient storage system. I'm gonna do that already. If you got BETTER suggestions, please lemme know.
Re: The Gogger - Advanced log system [BETA] -
Shadow_ - 15.09.2012
My point is you advertise it as an Advanced log creator which it is not. It is a simple but efficient log creator. I also wasn't talking about MySQL. Y_ini for example would be a better system which you could also make very advanced.
Also if you have never seen something like this on the forums i would advise you to check the code snippets thread or actually look through the forums.
https://sampforum.blast.hk/showthread.php?tid=77607 - theres one and look how old it is.
Re: The Gogger - Advanced log system [BETA] -
Gangster-rocks - 15.09.2012
Love it good for newbies bro.
AW: The Gogger - Advanced log system [BETA] -
BigETI - 15.09.2012
This version could be very usefull aswell:
pawn Код:
stock WriteLog(file_name[], ...)
{
new File:logfile, logargs = numargs()-1;
if(logargs == 0) return 0;
if(fexist(file_name)) logfile = fopen(file_name, io_append);
else logfile = fopen(file_name, io_write);
if(logfile)
{
new logstr[153], buffer[128], logdatetime[6];
getdate(logdatetime[0], logdatetime[1], logdatetime[2]);
gettime(logdatetime[3], logdatetime[4], logdatetime[5]);
for(new char i = 0; i < logargs; i++)
{
for(new char j = 0; j < sizeof buffer; j++)
{
buffer[i] = getarg(i+1, j);
if(buffer[i] == EOS) break;
}
format(logstr, sizeof logstr, "[%02d/%02d/%d %02d:%02d:%02d] %s\r\n", logdatetime[1], logdatetime[2], logdatetime[0], logdatetime[3], logdatetime[4], logdatetime[5], buffer);
fwrite(logfile, logstr);
}
fclose(logfile);
return 1;
}
else printf("Couldn't open log file '%s'.", file_name);
return 0;
}
Example:
pawn Код:
WriteLog("mylog.txt",
"This is a log entry.",
"I can add how much lines I want.",
"Isn't that smart though?");