Rock

iLogs | Server logs | 2.0

Mar 12th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.28 KB | None | 0 0
  1. #include <  a_samp  >
  2. #include < YSI\y_va >
  3.  
  4. #if defined _ServerLogs_included
  5.     #endinput
  6. #endif
  7.  
  8. #define _ServerLogs_included
  9. #define LogExist fexist
  10.  
  11. // if you feel that a string with '300' length is too much, #define in your script "LOG_MAX_STRING"
  12. #if !defined LOG_MAX_STRING
  13.     #define LOG_MAX_STRING ( 300 )
  14. #endif
  15.  
  16. stock WriteInLog( const Log_File[ ], Log_Par[ ], va_args< > )
  17. {
  18.     if( !LogExist( Log_File ) )
  19.     {
  20.         new
  21.             File:szLogF = fopen( Log_File, io_write );
  22.            
  23.         fclose( szLogF );
  24.     }
  25.  
  26.     static
  27.         szLogString[ LOG_MAX_STRING ],   iYear,      iHour,   iMonth,
  28.         szFormatArgs[ LOG_MAX_STRING ],   iDay,       iSecond, iMinute
  29.     ;
  30.  
  31.     va_format( szFormatArgs, sizeof( szFormatArgs ), Log_Par, va_start< 2 > );
  32.  
  33.     getdate( iYear, iMonth, iDay );
  34.     gettime( iHour, iMinute, iSecond );
  35.  
  36.     format( szLogString, 300, "(%d/%d/%d)[%02d:%02d:%d] %s\r\n", iDay, iMonth, iYear, iHour, iMinute , iSecond, szFormatArgs );
  37.  
  38.     new
  39.         File:szLog = fopen( Log_File, io_append );
  40.  
  41.     fwrite( szLog, szLogString );
  42.     fclose( szLog );
  43.  
  44.     return 1;
  45. }
  46.  
  47. stock DeleteLog( const Log_File[ ] )
  48. {
  49.     if( !LogExist( Log_File ) )
  50.     {
  51.         printf("This log doesn't exist.");
  52.         return 0;
  53.     }
  54.     fremove( Log_File );
  55.  
  56.     return 1;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment