[HELP]Writelog function, check please
#1

Well hello again guys, i was just wondering if you could check this function for me, tell me if anythings wrong, doesnt need, or if anything is missing, thanks.

pawn Код:
stock WriteLog(log[], string[])
{
    new File:handler;
    new buffer[512];
    new tmp[128];
    new bool:found;
    static wlday, wlmonth, wlyear;
    new day, month, year, hour, minute, second, weekday;
    new fname[128];

    getdate(year, month, day);
    gettime(hour, minute, second);
    weekday = getweekday(year, month, day) - 1;

    format(fname, 128, "biologicalwar/logs/%s.log", log);

    if(!fexist(fname))
    {
        handler = fopen(fname, io_write);
        printf("Server Log '%s' created!", log);

        format(buffer, 512, "@ Biological Warfare - %s log @\r\n\r\n\t ·-=-· %s, %s %d%s, %d ·-=-· \r\n\r\n[%02d:%02d:%02d] %s\r\n", log, WeekdayName[weekday], MonthName[month-1], day, GetOrdinalNumber(day), year, hour, minute, second, string);
        fwrite(handler, buffer);

        fclose(handler);

        wlyear = year, wlmonth = month, wlday = day;
        return true;
    }
    else
    {
      if(wlyear == year && wlmonth == month && wlday == day)
      {
        handler = fopen(fname, io_append);

        format(buffer, 512, "[%02d:%02d:%02d] %s\r\n", hour, minute, second, string);
            fwrite(handler, buffer);

            fclose(handler);

            return true;
        }
        else
        {
          handler = fopen(fname, io_read);

          format(tmp, 128, "%s, %s %d%s, %d", WeekdayName[weekday], MonthName[month-1], day, GetOrdinalNumber(day), year);

          while(fread(handler, buffer))
          {
            if(strfind(buffer, tmp) >= 0)
            {
              found = true;
              break;
                }
            }

            fclose(handler);
            handler = fopen(fname, io_append);

            if(found)
            {
              format(buffer, 512, "[%02d:%02d:%02d] %s\r\n", hour, minute, second, string);
                fwrite(handler, buffer);

                fclose(handler);

                wlyear = year, wlmonth = month, wlday = day;

                return true;
            }
            else
            {
              format(buffer, 512, "\r\n\t ·-=-· %s, %s %d%s, %d ·-=-· \r\n\r\n[%02d:%02d:%02d] %s\r\n", WeekdayName[weekday], MonthName[month-1], day, GetOrdinalNumber(day), year, hour, minute, second, string);
                fwrite(handler, buffer);

                fclose(handler);

                wlyear = year, wlmonth = month, wlday = day;
                return true;
            }
        }
    }
}
Reply
#2

Can't see anything wrong.
Reply
#3

alright so i would do it like

pawn Код:
WriteLog("spam.log", string);
or?
Reply
#4

WriteLog("spam", string);

would be correct

then it would write 'string' in the file 'spam.log'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)