Problem with logging to a file
#1

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.
Reply
#2

You should use a different argument for fopen, append not write.

pawn Код:
fopen(file, io_append);
io_write writes new text to file. And io_append appends text to it.
Reply
#3

Thanks, that really helped! +repped
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)