Server Log help
#1

pawn Код:
forward Serverlog(string[]);

public Serverlog(string[])
{
    new Year, Month2, Day;
    getdate(Year, Month2, Day);

    new Hour, Minute, Second;
    gettime(Hour, Minute, Second);

    new entry[256];
    format(entry, sizeof(entry), "[%02d.%02d.%d | %02d:%02d:%02d] %s\r\n",Day, Month2, Year, Hour, Minute, Second, string);
    new File:hFile;
    hFile = fopen("Server/Logs/DAY--MONTH--YEAR", io_append);
    fwrite(hFile, entry);
    fclose(hFile);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    Serverlog(text);
    return 1;
}
How can i make this like....
Today it is 7.Mrach.2011
Then the log should be named "7.March.2011"
And next day it should make a new log named "8.March.2011"
And then so on...


Server/Logs:
7.March.2011.log
8.March.2011.log
9.March.2011.log
Reply
#2

pawn Код:
forward Serverlog(string[]);

public Serverlog(string[])
{
    new entry[128 + 64];
    new Year, Month2, Day;
    getdate(Year, Month2, Day);
    new Hour, Minute, Second;
    gettime(Hour, Minute, Second);
    format(entry, sizeof(entry), "[%02d.%02d.%d | %02d:%02d:%02d] %s\r\n",Day, Month2, Year, Hour, Minute, Second, string);
    new File:hFile, string[64];
    format(string, sizeof(string), "Server/Logs/%02d.%s.%02d.log", Day, GetMonthName(month), Year);
    hFile = fopen(string, io_append);
    fwrite(hFile, entry);
    fclose(hFile);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    Serverlog(text);
    return 1;
}

stock GetMonthName(month)
{
    new mname[16];
    switch(month)
    {
        case 1: mname = "January";
        case 2: mname = "February";
        case 3: mname = "March";
        case 4: mname = "April";
        case 5: mname = "May";
        case 6: mname = "June";
        case 7: mname = "July";
        case 8: mname = "August";
        case 9: mname = "September";
        case 10: mname = "October";
        case 11: mname = "November";
        case 12: mname = "December";
    }
    return mname;
}
Reply
#3

Hi i edited it and i got a Warning

Code

pawn Код:
#include <a_samp>

forward Serverlog(string[]);

public Serverlog(string[])
{
    new Year, Month2, Day;
    getdate(Year, Month2, Day);
   
    new Hour, Minute, Second;
    gettime(Hour, Minute, Second);
   
    new entry[128 + 64];
    format(entry, sizeof(entry), "[%02d.%02d.%d | %02d:%02d:%02d] %s\r\n",Day, Month2, Year, Hour, Minute, Second, string);

    new File:hFile;
    format(string, sizeof(string), "Server/Logs/%02d.%s.%02d.log", Day, GetMonth(), Year); //Шine 17
    hFile = fopen(string, io_append);
    fwrite(hFile, entry);
    fclose(hFile);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    Serverlog(text);
    return 1;
}

stock GetMonth()
{
    new monthname[10], Year, Month1, Day;
    getdate(Year, Month1, Day);

    switch(Month1)
    {
        case 1:  monthname = "January";
        case 2:  monthname = "February";
        case 3:  monthname = "March";
        case 4:  monthname = "April";
        case 5:  monthname = "May";
        case 6:  monthname = "June";
        case 7:  monthname = "July";
        case 8:  monthname = "August";
        case 9:  monthname = "September";
        case 10: monthname = "October";
        case 11: monthname = "November";
        case 12: monthname = "December";
    }
    return monthname;
}
Warning
Код:
C:\Users\Unknown123\Documents\Server\filterscripts\ServerLog.pwn(17) : warning 224: indeterminate array size in "sizeof" expression (symbol "")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
But will this log like this?

6.March.2011
7.March.2011
Then so on

Like it should be in my "Logs folder":
6.March.2011.log
7.March.2011.log
8.March.2011.log
9.March.2011.log
Reply
#4

Should work fine.

pawn Код:
#include <a_samp>

forward ServerLog( string[ ] );

public ServerLog( string[ ] )
{
    new
        day,
        month,
        year,
        hour,
        minute,
        second,
        entry[ 192 ],
        filename[ 32 ],
        File:file;
    getdate( year, month, day );
    gettime( hour, minute, second);
    // Is it necessary to log which date it is in the entry? It's held in the file name. Your choice.
    format( entry, sizeof ( entry ), "[%02i.%02i.%i | %02i:%02i:%02i] %s\r\n", day, month, year, hour, minute, second, string );
    format( filename, sizeof ( filename ), "Server/Logs/%02i.%s.%i.log", day, GetMonth( ), year ); //
    file = ( ( fexist( filename ) ) ? ( fopen( filename, io_append ) ) : ( fopen( filename, io_write ) ) );
    fwrite( file, entry );
    fclose( file );
    return 1;
}

public OnPlayerText( playerid, text[ ] )
{
    ServerLog( text );
    return 1;
}

stock GetMonth( )
{
    new
        day,
        month,
        year,
        monthname[ 10 ] = "invalid";
    getdate( day, month, year );
    switch ( month )
    {
        case 1:  monthname = "January";
        case 2:  monthname = "February";
        case 3:  monthname = "March";
        case 4:  monthname = "April";
        case 5:  monthname = "May";
        case 6:  monthname = "June";
        case 7:  monthname = "July";
        case 8:  monthname = "August";
        case 9:  monthname = "September";
        case 10: monthname = "October";
        case 11: monthname = "November";
        case 12: monthname = "December";
    }
    return monthname;
}
Reply
#5

Thanks, And this will create a new log everyday? Like:

6.March.2011.log
7.March.2011.log
...Then so on...
Reply
#6

Yes.
Reply
#7

Quote:
Originally Posted by bigcomfycouch
Посмотреть сообщение
Yes.
Ok Thanks Then
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)