[HELP] Logs
#1

How can i do a log in my server with dini?? I want to print in a file the status changes of my server like when players connect and disconnect or when I shut down the server or start it.
Reply
#2

Don't use dini, very outdated and slow. It's also not created to take on tasks like these. This is where the default file functions are perfect
pawn Код:
// top of script
#define LOG_FILE   "log.txt"

public OnPlayerConnect( playerid )
{
   new File: hFile = fopen( LOG_FILE, io_append );
   if( hFile )
   {
      new str[ MAX_PLAYER_NAME + 15 ], name[ MAX_PLAYER_NAME ];
      GetPlayerName( playerid, name, MAX_PLAYER_NAME );
      format( str, sizeof( str ), "%s has connected.", name );
      fwrite( hFile, str );
   }
   fclose( hFile );
   return 1;
}
You can simply repeat that process for different things.
Reply
#3

Thanks!!! But i don't need to insert /n for a new line
Reply
#4

Yes you need it. And here's a nice log function (made by me

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;
}
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.
Reply
#5

This is a nice script thank you!!!!
Reply
#6

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
Yes you need it. And here's a nice log function (made by me

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;
}
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.
That contains a severe amount of redundant code, you should consider just using Unix Timestamps and converting them to normal date/time strings when you absolutely must.
Reply
#7

How to get Unix Timestamp? I know what it is etc (right now it's 1294199340)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)