forked from klusta-team/klustakwik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.cpp
56 lines (46 loc) · 962 Bytes
/
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
/*
* log.cpp
*
* Used for logging output to stdout and to a file.
*
* Created on: 11 Nov 2011
* Author: dan
*/
// Disable some Visual Studio warnings
#define _CRT_SECURE_NO_WARNINGS
#include "log.h"
#include "parameters.h"
#include<stdio.h>
#include <stdarg.h>
FILE *logfp;
// Write to screen and log file
void Output(char *fmt, ...) {
va_list arg;
char str[STRLEN];
if (!Screen && !Log) return;
va_start(arg, fmt);
vsnprintf(str,STRLEN,fmt,arg);
va_end(arg);
if (Screen) printf("%s", str);
if (Log) fprintf(logfp, "%s", str);
FlushLog();
}
// Print an error message and abort
void Error(char *fmt, ...) {
va_list arg;
char str[STRLEN];
if (!Screen && !Log) return;
va_start(arg, fmt);
vsnprintf(str,STRLEN,fmt,arg);
va_end(arg);
if (Screen) fprintf(stderr, "%s", str);
if (Log) fprintf(logfp, "%s", str);
FlushLog();
}
void FlushLog()
{
if (Log)
{
fflush(logfp);
}
}