upiwin/src/log.c
Amy Bowersox d1369964d7 The code has to be GPL'd, because the license of the BCM2835 library requires
it.  Add the license document and the header on all source files.
2019-12-12 09:24:58 -07:00

53 lines
1.7 KiB
C

/*
* UPIWIN - Micro Pi Windowing Framework Kernel
* Copyright (C) 2019 Amy Bowersox/Erbosoft Metaverse Design Solutions
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <sys/time.h>
#include "log.h"
/* string equivalents to the severity values */
static const char *severities[] = { "FATAL", "ERROR", "WARN ", "INFO ", "DEBUG" };
static FILE *logfile = NULL; /* log file pointer */
void Log(int level, const char *format, ...)
{
va_list argp;
struct timeval tv;
struct tm tm;
char timestamp[32];
char buf[1024];
va_start(argp, format);
vsnprintf(buf, 1024, format, argp);
va_end(argp);
gettimeofday(&tv, NULL);
localtime_r(&(tv.tv_sec), &tm);
strftime(timestamp, 32, "%F %T", &tm);
fprintf(logfile ? logfile : stdout, "%s.%06ld %s %s\n", timestamp, tv.tv_usec, severities[level], buf);
}
void Log_assert_failed(const char *test, const char *file, int line)
{
Log(LERROR, "ASSERT FAILED: %s at %s:%d", test, file, line);
}