04.01.2011, 15:06
Yes you need it. And here's a nice log function (made by me
Example:
[code]
AddLog("LOG.txt", "Hi there!");
If that's used on 01-01-2011 (DAY-MONTH-YEAR) and time 0:0:0,
in the file "scriptfiles/LOG.txt" there will be a new line: [01-01-2011 00:00:00] Hi there!
When you use it 2 seconds later again, the file will look like this:
[01-01-2011 00:00:00] Hi there!
[01-01-2011 00:00:02] Hi there!
Got it? It gives automatic date+time. And the new line is automatic too.
pawn Код:
stock AddLog(filename[], log[]) //Usage: AddLog(Name_Of_File, Log_Content (string or something);
{
new day, month, year, hour, minute, second;
new str[200], File:_lfile;
getdate(year, month, day); gettime(hour, minute, second);
format(str, 200, "[%02d-%02d-%02d %02d:%02d:%02d] %s\r\n", day, month, year, hour, minute, second, log);
_lfile = fopen(filename, io_append);
fwrite(_lfile, str);
fclose(_lfile);
return 1;
}
[code]
AddLog("LOG.txt", "Hi there!");
If that's used on 01-01-2011 (DAY-MONTH-YEAR) and time 0:0:0,
in the file "scriptfiles/LOG.txt" there will be a new line: [01-01-2011 00:00:00] Hi there!
When you use it 2 seconds later again, the file will look like this:
[01-01-2011 00:00:00] Hi there!
[01-01-2011 00:00:02] Hi there!
Got it? It gives automatic date+time. And the new line is automatic too.