Guest User

Untitled

a guest
Jul 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. #ifndef __LOG_H__
  2. #define __LOG_H__
  3.  
  4. #include "common.h"
  5.  
  6. #define BLACK 0
  7. #define BLUE 1
  8. #define GREEN 2
  9. #define CYAN 3
  10. #define RED 4
  11. #define MAGENTA 5
  12. #define BROWN 6
  13. #define LIGHTGREY 7
  14. #define DARKGREY 8
  15. #define LIGHTBLUE 9
  16. #define LIGHTGREEN 10
  17. #define LIGHTCYAN 11
  18. #define LIGHTRED 12
  19. #define LIGHTMAGENTA 13
  20. #define YELLOW 14
  21. #define WHITE 15
  22. #define BLINK 128
  23.  
  24. #define LOGFILE "InternalServer.log"
  25. class Log
  26. {
  27. public:
  28.     static void SetConsoleTextColor( uint8_t color )
  29.     {
  30.         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), color );
  31.     }
  32.  
  33.     static void Error( const char* calledBy, const char* line, ... )
  34.     {
  35.         while( working ) Sleep( 10 );
  36.  
  37.         working = true;
  38.  
  39.         FILE *fp = fopen( LOGFILE, "a+" );
  40.         char time[ 9 ];
  41.         char logline[ 1024 ];
  42.  
  43.         _strtime( time );
  44.         SetConsoleTextColor( DARKGREY );
  45.  
  46.         printf( "%s", time );
  47.         fprintf( fp, "%s", time );
  48.  
  49.         SetConsoleTextColor( LIGHTRED );
  50.  
  51.         printf( " D " );
  52.         fprintf( fp, " D " );
  53.  
  54.         SetConsoleTextColor( WHITE );
  55.  
  56.         printf( "%s: ", calledBy );
  57.         fprintf( fp, "%s: ", calledBy );
  58.  
  59.         SetConsoleTextColor( LIGHTRED );
  60.  
  61.         va_list argumentList;
  62.         va_start( argumentList, line );
  63.  
  64.         vsnprintf( logline, 1024, line, argumentList );
  65.  
  66.         va_end( argumentList );
  67.  
  68.         printf( "%s\n", logline );
  69.         fprintf( fp, "%s\n", logline );
  70.  
  71.         fclose( fp );
  72.  
  73.         working = false;
  74.     }
  75.  
  76.     static void Debug( const char* calledBy, const char* line, ... )
  77.     {
  78.         while( working ) Sleep( 10 );
  79.  
  80.         working = true;
  81.  
  82.         FILE *fp = fopen( LOGFILE, "a+" );
  83.         char time[ 9 ];
  84.         char logline[ 1024 ];
  85.  
  86.         _strtime( time );
  87.         SetConsoleTextColor( DARKGREY );
  88.  
  89.         printf( "%s", time );
  90.         fprintf( fp, "%s", time );
  91.  
  92.         SetConsoleTextColor( LIGHTCYAN );
  93.  
  94.         printf( " D " );
  95.         fprintf( fp, " D " );
  96.  
  97.         SetConsoleTextColor( WHITE );
  98.  
  99.         printf( "%s: ", calledBy );
  100.         fprintf( fp, "%s: ", calledBy );
  101.  
  102.         SetConsoleTextColor( LIGHTCYAN );
  103.  
  104.         va_list argumentList;
  105.         va_start( argumentList, line );
  106.  
  107.         vsnprintf( logline, 1024, line, argumentList );
  108.  
  109.         va_end( argumentList );
  110.  
  111.         printf( "%s\n", logline );
  112.         fprintf( fp, "%s\n", logline );
  113.  
  114.         fclose( fp );
  115.  
  116.         working = false;
  117.     }
  118.  
  119.     static void Trace( const char* calledBy, const char* line, ... )
  120.     {
  121.         while( working ) Sleep( 10 );
  122.  
  123.         working = true;
  124.  
  125.         FILE *fp = fopen( LOGFILE, "a+" );
  126.         char time[ 9 ];
  127.         char logline[ 1024 ];
  128.  
  129.         _strtime( time );
  130.         SetConsoleTextColor( DARKGREY );
  131.  
  132.         printf( "%s", time );
  133.         fprintf( fp, "%s", time );
  134.  
  135.         SetConsoleTextColor( LIGHTGREEN );
  136.  
  137.         printf( " T " );
  138.         fprintf( fp, " T " );
  139.  
  140.         SetConsoleTextColor( WHITE );
  141.  
  142.         printf( "%s: ", calledBy );
  143.         fprintf( fp, "%s: ", calledBy );
  144.  
  145.         SetConsoleTextColor( LIGHTGREEN );
  146.  
  147.         va_list argumentList;
  148.         va_start( argumentList, line );
  149.  
  150.         vsnprintf( logline, 1024, line, argumentList );
  151.  
  152.         va_end( argumentList );
  153.  
  154.         printf( "%s\n", logline );
  155.         fprintf( fp, "%s\n", logline );
  156.  
  157.         fclose( fp );
  158.  
  159.         working = false;
  160.     }
  161.  
  162.     static bool working;
  163. };
  164.  
  165. #endif /* __LOG_H__ */
Add Comment
Please, Sign In to add comment