Issues writing to files
#1

I made a logging function for one of my scripts:
pawn Код:
public WriteToLogFile(string[])
{
    new Hour, Minute, Second, Year, Month, Day;
    getdate(Year, Month, Day);
    gettime(Hour, Minute, Second);
    LogFile = fopen("ACLog.txt", io_append);
    new logstring[256];
    format(logstring, sizeof(logstring), "[%s-%s-%s at %s:%s:%s] %s \r\n", Year, Month, Day, Hour, Minute, Second, string);
    fwrite(LogFile, string);
    fclose(LogFile);
}
Only issue with it is that it isn't including the date or time, nor is it putting the nest string on the next line.
What's wrong with it?

EDIT: I kicked myself from my server and I got this out of my log file:
Код:
biltong has been kicked by biltong.
That's it, nothing else. Why isn't it showing the date or time?
Reply
#2

%s is for text and u need %d for value
Код:
[%d-%02d-%02d at %02d:%02d:%02d]
Reply
#3

%s which you used is practically for longer strings while %d is used for numbers.
Reply
#4

stop to say bullshits.
fwrite(LogFile, string); -> change to: fwrite(LogFile, logstring);
enjoy (?)
Reply
#5

Quote:
Originally Posted by `Internal
stop to say bullshits.
fwrite(LogFile, string); -> change to: fwrite(LogFile, logstring);
enjoy (?)
I'm so stupid. Thanks guys! Though it's still not printing the next entry to another line, when I did that and kicked myself again I got:
Код:
biltong has been kicked by biltong.|2010-3-29 at 10:11:54|biltong has been kicked by biltong. Reason: klsjdfgbxdcfvnhlksjerdhf
Reply
#6

Ok I sorted that problem out. Still don't know what was causing it. Now I'm trying to save the LogFile in a directory, but every time I do, my server crashes on startup.

pawn Код:
LogFile = fopen("AdminClick/ACLog.txt", io_write);
Thats the bit that crashes it. My script has no warnings nor errors, it works fine if I get rid of the "AdminClick/" bit. I see in other scripts they do it like this and theirs work, but mine doesn't.

Credits will be given in script for who fixes it.

EDIT: I made the directory myself and now it works. Does that mean SA:MP can't make it's own directories?
Reply
#7

No, it can't, but YSF can.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)