15 static const WORD MAX_CONSOLE_LINES = 500;
17 void logit(int type, const char * format, ...)
19 static int hConHandle = 0;
21 if (0 && hConHandle == 0) {
22 CONSOLE_SCREEN_BUFFER_INFO coninfo;
24 if (AttachConsole(ATTACH_PARENT_PROCESS) == ERROR_INVALID_HANDLE) {
27 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
28 coninfo.dwSize.Y = MAX_CONSOLE_LINES;
29 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
35 // redirect unbuffered STDOUT to the console
36 lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
37 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
38 fp = _fdopen( hConHandle, "w" );
40 setvbuf( stdout, NULL, _IONBF, 0 );
42 // redirect unbuffered STDIN to the console
43 lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
44 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
45 fp = _fdopen( hConHandle, "r" );
48 setvbuf( stdin, NULL, _IONBF, 0 );
50 // redirect unbuffered STDERR to the console
51 lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
52 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
53 fp = _fdopen( hConHandle, "w" );
56 setvbuf( stderr, NULL, _IONBF, 0 );
63 gettimeofday(&now, NULL);
65 struct tm * now_tm = localtime(&(now.tv_sec));
67 if (type == LOG_INFO) {
68 vfprintf(stdout, format, va);
69 fprintf(stdout, "\n");
71 if (type == LOG_DEBUG) {
73 fprintf(stderr, "%02d:%02d:%02d.%03d ", now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, (int)(now.tv_usec / 1000));
74 vfprintf(stderr, format, va);
75 fprintf(stderr, "\n");
78 vfprintf(stderr, format, va);
79 fprintf(stderr, "\n");
87 void logit(int type, const char * format, ...)
93 gettimeofday(&now, NULL);
95 struct tm * now_tm = localtime(&(now.tv_sec));
97 if (type == LOG_INFO) {
98 vfprintf(stdout, format, va);
99 fprintf(stdout, "\n");
101 if (type == LOG_DEBUG) {
103 fprintf(stderr, "%02d:%02d:%02d.%03d ", now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, (int)(now.tv_usec / 1000));
104 vfprintf(stderr, format, va);
105 fprintf(stderr, "\n");
108 vfprintf(stderr, format, va);
109 fprintf(stderr, "\n");