1
0
mirror of https://github.com/pevans/erc-c.git synced 2025-01-21 14:30:39 +00:00
erc-c/src/log.c

37 lines
549 B
C
Raw Normal View History

2017-11-21 23:24:51 -06:00
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
2017-12-02 13:05:53 -06:00
#include "log.h"
2017-11-21 23:24:51 -06:00
static FILE *log_stream = NULL;
void
log_open()
{
2017-12-02 13:05:53 -06:00
log_stream = fopen(LOG_FILENAME, "w");
2017-11-21 23:24:51 -06:00
if (log_stream == NULL) {
2017-12-02 13:05:53 -06:00
perror("Couldn't open log file (" LOG_FILENAME ")");
2017-11-21 23:24:51 -06:00
exit(1);
}
}
void
log_close()
{
if (log_stream != NULL) {
fclose(log_stream);
}
}
void
log_write(int level, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(log_stream, fmt, ap);
fprintf(log_stream, "\n");
va_end(ap);
}