summaryrefslogtreecommitdiffstats
path: root/loader/log.c
blob: 47b22761ae3ba5d9b99080787177eac3f49d738a (plain)
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
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "log.h"

static FILE * logfile = NULL;
static int logfd;
static int logDebugMessages = 0;

static void doLogMessage(const char * s, va_list args);

void logMessage(const char * s, ...) {
    va_list args;

    if (!logfile) return;

    va_start(args, s);

    fprintf(logfile, "* ");
    vfprintf(logfile, s, args);
    fprintf(logfile, "\n");
    fflush(logfile);

    va_end(args);

    return;
}

void openLog(int useLocal) {
    if (!useLocal) {
	logfile = fopen("/dev/tty3", "w");
	if (logfile)
	    logfd = open("/dev/tty3", O_WRONLY);
	else {
	    logfile = fopen("/tmp/install.log", "a");
	    logfd = open("/tmp/install.log", O_WRONLY| O_APPEND);
	}
    } else {
	logfile = fopen("debug.log", "w");
	logfd = open("debug.log", O_WRONLY);
    }

    if (getenv("DEBUG")) logDebugMessages = 1;
}

void closeLog(void) {
    if (logfile) {
	fclose(logfile);
	close(logfd);
    }
}