Writing to log format
#1

Hi.

I need to make log writing function.
I made this:

Код:
stock WriteToLog(log[], const input[], {Float,_}:...)
{
	new string[128];
	new File:Plik = fopen(log, io_append);
	format(string, sizeof(string), input, ...);
	fwrite(Plik, string);
	fclose(Plik);
}
But i have this error:
Quote:

error 029: invalid expression, assumed zero

On line:
Quote:

format(string, sizeof(string), input, ...);

Can someone help?
Reply
#2

Make a folder in your scriptfiles folder and name it something, like your server short form name for example, or Plik as I see it is the name in your code.

pawn Код:
// Top of your script

#define SAVE_LOGS

// Bottom of your script:

forward SaveToFile(filename[],text[]);
public SaveToFile(filename[],text[])
{
    #if defined SAVE_LOGS
    new File:Plik, filepath[256], string[256], year,month,day, hour,minute,second;
    getdate(year,month,day); gettime(hour,minute,second);

    format(filepath,sizeof(filepath),"ladmin/logs/%s.txt",filename);
    Plik = fopen(filepath,io_append);
    format(string,sizeof(string),"[%d.%d.%d %d:%d:%d] %s\r\n",day,month,year,hour,minute,second,text);
    fwrite(Plik,string);
    fclose(Plik);
    #endif
    return 1;
}
Now, make a text file in scriptfiles/Plik with a .txt extension at the end, like KickLog.txt

Next, type SaveToFile("KickLog",string); under your kick command, as this is the example for now (You can change it up if you want)

Now when the next person gets kicked, it will save a log of it in scriptfiles/Plik/KickLog.txt
Reply
#3

Quote:

[256]

I suggests using 128. Its enaugh nad its 2x faster.

Quote:

forward SaveToFile(filename[],text[]);

This is not what i need. I need fucntion with formating string !
For example:
Код:
WriteToLog("Logs/test.txt", "%s (ID:%d) is now testing log.", PlayerName(playerid), playerid);
How to make this ?
Reply
#4

Can someone help ?
Reply
#5

Ok Ok ! I made this !

Код:
new FALSE = 0;
#define WriteToLog(%0,%1,%2) \
do \
{ \
	new tmp[128]; \
	format(tmp, 128, %1, %2); \
	new File:Plik = fopen(%0, io_append); \
	fwrite(Plik, tmp); \
	fclose(Plik); \
} \
while(FALSE)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)