Problem with logging to a file - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with logging to a file (
/showthread.php?tid=402816)
Problem with logging to a file -
YoYo123 - 28.12.2012
I tried making a file logging system but whenever I enter a command more than once it won't make a new line and replace the first line with the current line.
Here is my LogToFile stock:
pawn Код:
stock LogToFile(filename[], log[])
{
new file[128], fullLog[200];
format(file, sizeof file, "AdminSys/Logs/%s.log", filename);
if(!dini_Exists(file)) dini_Create(file);
new File:hFile = fopen(file, io_write);
new year, month, day, hour, minute, second;
getdate(year, month, day);
gettime(hour, minute, second);
format(fullLog, sizeof fullLog, "[%d/%d/%d - %d:%d:%d] %s\r\n", day, month, year, hour, minute, second, log);
fwrite(hFile, fullLog);
fclose(hFile);
return 1;
}
And when an admin uses a command I put this in the command function:
pawn Код:
LogToFile("commandName", formattedLog);
+rep for helpers.
Re: Problem with logging to a file -
iggy1 - 28.12.2012
You should use a different argument for fopen, append not write.
io_write writes new text to file. And io_append appends text to it.
Re: Problem with logging to a file -
YoYo123 - 28.12.2012
Thanks, that really helped! +repped