/*
 * Functions for logging and catching errors.
 *
 * @copyright 2008, Research In Motion Ltd.
 *
 * @version $Id: //depot/main/dsp/ecall/c/testlab/error.c#2 $
 */

#include <stdio.h>
#include <windows.h>
#include "error.h"

static FILE *fpLog = NULL;

void LogInit(FILE *fp)
{
    fpLog = fp;
}

void LogInfo(const char *format, ...) {
    if(fpLog) {
        va_list args;
        va_start(args, format);
        fprintf(fpLog, "INFO  ");
        vfprintf(fpLog, format, args);
        fprintf(fpLog, "\n");
        va_end(args);
        fflush(stderr);
    }
}

void LogError(const char *format, ...) {
    if(fpLog) {
        va_list args;
        va_start(args, format);
        fprintf(fpLog, "ERROR ");
        vfprintf(fpLog, format, args);
        fprintf(fpLog, "\n");
        va_end(args);
        fflush(stderr);
    }
}

void Abort(const char *format, ...) {
    if(fpLog) {
        va_list args;
        va_start(args, format);
        fprintf(fpLog, "ABORT ");
        vfprintf(fpLog, format, args);
        fprintf(fpLog, "\n");
        va_end(args);
        fflush(stderr);
    }

    ExitProcess(-1);
}
