File: log.cpp

package info (click to toggle)
klustakwik 3.0.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 684 kB
  • sloc: cpp: 2,101; makefile: 176; sh: 15
file content (43 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (2)
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
/*
 * log.cpp
 *
 * Used for logging output to stdout and to a file.
 *
 *  Created on: 11 Nov 2011
 *      Author: dan
 */

#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);
}

// 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);
}