<commit_before>#include <config.h>

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <syslog.h>
#include <string.h>

#include <mopher.h>

#define BUFLEN 1024

static int log_level;
static int log_syslog;

void
log_init(char *name, int level, int syslog, int foreground)
{
	int option;

	log_syslog = syslog;
	log_level = level;

	if (!syslog)
	{
		return;
	}

	option = foreground ? LOG_PID | LOG_PERROR : LOG_PID;
	openlog(name, option, LOG_MAIL);
	return;
}

void
log_close(void)
{
	if (log_syslog)
	{
		closelog();
	}

	return;
}

static void
log_append_syserr(char *buffer, int buflen)
{
	strncat(buffer + strlen(buffer), ": ", buflen - strlen(buffer));
	strncat(buffer + strlen(buffer), strerror(errno),
		buflen - strlen(buffer));

	return;
}

static void
log_logv(int type, int syserr, char *f, va_list ap)
{
	char buffer[BUFLEN];

	if (type > log_level)
	{
		errno = 0;
		return;
	}

	vsnprintf(buffer, BUFLEN, f, ap);

	if (syserr)
	{
		log_append_syserr(buffer, BUFLEN);
	}

	if (log_syslog)
	{
		syslog(type, buffer);
	}
	else
	{
		fprintf(stderr, buffer);
		fputc('\n', stderr);
	}

	return;
}


void
log_log(int type, int syserr, char *f, ...)
{
	va_list ap;

	va_start(ap, f);
	log_logv(type, f, ap);
	va_end(ap);

	return;
}


void
log_exit(int r, int syserr, char *f, ...)
{
	va_list ap;

	va_start(ap, f);
	log_logv(LOG_ERR, syserr, f, ap);
	va_end(ap);

	log_close();
	exit(r);

	return;
}<commit_msg>Fixed bad call to log_logv in log_log<commit_after>#include <config.h>

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <syslog.h>
#include <string.h>

#include <mopher.h>

#define BUFLEN 1024

static int log_level;
static int log_syslog;

void
log_init(char *name, int level, int syslog, int foreground)
{
	int option;

	log_syslog = syslog;
	log_level = level;

	if (!syslog)
	{
		return;
	}

	option = foreground ? LOG_PID | LOG_PERROR : LOG_PID;
	openlog(name, option, LOG_MAIL);
	return;
}

void
log_close(void)
{
	if (log_syslog)
	{
		closelog();
	}

	return;
}

static void
log_append_syserr(char *buffer, int buflen)
{
	strncat(buffer + strlen(buffer), ": ", buflen - strlen(buffer));
	strncat(buffer + strlen(buffer), strerror(errno),
		buflen - strlen(buffer));

	return;
}

static void
log_logv(int type, int syserr, char *f, va_list ap)
{
	char buffer[BUFLEN];

	if (type > log_level)
	{
		errno = 0;
		return;
	}

	vsnprintf(buffer, BUFLEN, f, ap);

	if (syserr)
	{
		log_append_syserr(buffer, BUFLEN);
	}

	if (log_syslog)
	{
		syslog(type, buffer);
	}
	else
	{
		fprintf(stderr, buffer);
		fputc('\n', stderr);
	}

	return;
}


void
log_log(int type, int syserr, char *f, ...)
{
	va_list ap;

	va_start(ap, f);
	log_logv(type, syserr, f, ap);
	va_end(ap);

	return;
}


void
log_exit(int r, int syserr, char *f, ...)
{
	va_list ap;

	va_start(ap, f);
	log_logv(LOG_ERR, syserr, f, ap);
	va_end(ap);

	log_close();
	exit(r);

	return;
}
{'fraction_non_alphanumeric': 0.15438713998660417, 'fraction_numerical': 0.003348961821835231, 'mean_word_length': 4.045608108108108, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3887241', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1305, 'n_words': 301}