15 static const WORD MAX_CONSOLE_LINES = 500;
17 void logit(int type, const char * format, ...)
19 static int hConHandle = 0;
21 if (hConHandle == 0) {
22 CONSOLE_SCREEN_BUFFER_INFO coninfo;
24 //AttachConsole(ATTACH_PARENT_PROCESS);
25 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
26 coninfo.dwSize.Y = MAX_CONSOLE_LINES;
27 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
33 // redirect unbuffered STDOUT to the console
34 lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
35 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
36 fp = _fdopen( hConHandle, "w" );
38 setvbuf( stdout, NULL, _IONBF, 0 );
40 // redirect unbuffered STDIN to the console
41 lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
42 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
43 fp = _fdopen( hConHandle, "r" );
46 setvbuf( stdin, NULL, _IONBF, 0 );
48 // redirect unbuffered STDERR to the console
49 lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
50 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
51 fp = _fdopen( hConHandle, "w" );
54 setvbuf( stderr, NULL, _IONBF, 0 );
61 gettimeofday(&now, NULL);
63 struct tm * now_tm = localtime(&(now.tv_sec));
65 if (type == LOG_INFO) {
66 vfprintf(stdout, format, va);
67 fprintf(stdout, "\n");
69 if (type == LOG_DEBUG) {
71 fprintf(stderr, "%02d:%02d:%02d.%03d ", now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, (int)(now.tv_usec / 1000));
72 vfprintf(stderr, format, va);
73 fprintf(stderr, "\n");
76 vfprintf(stderr, format, va);
77 fprintf(stderr, "\n");
85 void logit(int type, const char * format, ...)
91 gettimeofday(&now, NULL);
93 struct tm * now_tm = localtime(&(now.tv_sec));
95 if (type == LOG_INFO) {
96 vfprintf(stdout, format, va);
97 fprintf(stdout, "\n");
99 if (type == LOG_DEBUG) {
101 fprintf(stderr, "%02d:%02d:%02d.%03d ", now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, (int)(now.tv_usec / 1000));
102 vfprintf(stderr, format, va);
103 fprintf(stderr, "\n");
106 vfprintf(stderr, format, va);
107 fprintf(stderr, "\n");