[Include] The Gogger - Advanced log system [BETA]
#12

This version could be very usefull aswell:
pawn Код:
stock WriteLog(file_name[], ...)
{
    new File:logfile, logargs = numargs()-1;
    if(logargs == 0) return 0;
    if(fexist(file_name)) logfile = fopen(file_name, io_append);
    else logfile = fopen(file_name, io_write);
    if(logfile)
    {
        new logstr[153], buffer[128], logdatetime[6];
        getdate(logdatetime[0], logdatetime[1], logdatetime[2]);
        gettime(logdatetime[3], logdatetime[4], logdatetime[5]);
        for(new char i = 0; i < logargs; i++)
        {
            for(new char j = 0; j < sizeof buffer; j++)
            {
                buffer[i] = getarg(i+1, j);
                if(buffer[i] == EOS) break;
            }
            format(logstr, sizeof logstr, "[%02d/%02d/%d %02d:%02d:%02d] %s\r\n", logdatetime[1], logdatetime[2], logdatetime[0], logdatetime[3], logdatetime[4], logdatetime[5], buffer);
            fwrite(logfile, logstr);
        }
        fclose(logfile);
        return 1;
    }
    else printf("Couldn't open log file '%s'.", file_name);
    return 0;
}
Example:
pawn Код:
WriteLog("mylog.txt",
    "This is a log entry.",
    "I can add how much lines I want.",
    "Isn't that smart though?");
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)