-
Notifications
You must be signed in to change notification settings - Fork 4
/
log.cpp
60 lines (48 loc) · 1.03 KB
/
log.cpp
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
52
53
54
55
56
57
58
59
60
#include "config.h"
#include "log.h"
#include "arch/platform.h"
#include <stdio.h>
#include <stdarg.h>
static bool log_flush=false;
int log_level=0;
static FILE *debug_log;
bool init_log( const char * file_name, bool flush )
{
if( debug_log==NULL ) {
debug_log=fopen(file_name, "at");
if( debug_log==NULL ) {
perror("fakeroot-ng: Could not open debug log");
return false;
} else {
log_level=1;
}
log_flush=flush;
}
return true;
}
void close_log()
{
if( debug_log!=NULL )
fclose(debug_log);
}
void __dlog_( const char *format, ... )
{
if( debug_log!=NULL ) {
if( format!=NULL ) {
va_list params;
va_start(params, format);
vfprintf(debug_log, format, params);
va_end(params);
}
if( format==NULL || log_flush ) {
fflush( debug_log );
}
}
}
int get_log_fd()
{
if( debug_log!=NULL )
return fileno(debug_log);
else
return -1;
}