-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.cc
53 lines (45 loc) · 927 Bytes
/
logger.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
#include <cstdio>
#include <cctype>
#include <cstdarg>
#include "logger.h"
using namespace std;
FILE *output;
char *buffer;
int buffer_size;
void log_init(string name = "")
{
buffer = new char[5*1024*1024];
buffer[0] = '\0';
buffer_size = 0;
if (name != "")
output = fopen(name.c_str(), "w");
else
output = stdout;
}
void log_close()
{
buffer[buffer_size]='\0';
fwrite (buffer , sizeof(char), buffer_size, output);
//fprintf(output, "%s", buffer);
if (output != stdout)
fclose(output);
delete buffer;
}
void log(const char* format, ...)
{
va_list args;
va_start (args, format);
buffer_size += vsprintf(buffer+buffer_size, format, args);
va_end(args);
if (buffer_size > 5200000)
{
buffer[buffer_size]='\0';
fwrite (buffer , sizeof(char), buffer_size, output);
//fprintf(output, "%s", buffer);
fflush(output);
buffer_size=0;
buffer[0] = '\0';
}
}