<commit_before>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>

#include "log.h"

void
log_init(int *argc, char ***argv, int logopt, int logfac)
{
  char *progname;
  
  progname = (progname = strrchr((*argv)[0], '/')) ? progname+1 : (*argv)[0];
  openlog(progname, logopt, logfac);
}

void
log_raw(int priority, const char *format, ...)
{
  char *prefix;
  FILE *out;
  va_list args;

  out=stderr;
  switch (priority) {
    case LOG_EMERG:
      prefix="<EMERG>";
      break;
    case LOG_ALERT:
      prefix="<ALERT>";
      break;
    case LOG_ERR:
      prefix="<ERR>  ";
      break;
    case LOG_WARNING:
      prefix="<WARN> ";
      break;
    case LOG_NOTICE:
      prefix="<NOTE> ";
      out=stdout;
      break;
    case LOG_INFO:
      prefix="<INFO> ";
      out=stdout;
      break;
    case LOG_DEBUG:
      prefix="<DEBUG>";
      out=stdout;
      break;
    default:
      prefix="<INFO> ";
      out=stdout;
  }

  va_start(args, format);
  vsyslog(priority, format, args);
  va_end(args);

  if (out) {
    va_start(args, format);
    (void)fprintf(out, "%s ", prefix);
    (void)vfprintf(out, format, args);
    (void)fprintf(out, "\n");
    va_end(args);
  }
}
<commit_msg>Only emit a newline if the logline doesn't already contain one<commit_after>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>

#include "log.h"

void
log_init(int *argc, char ***argv, int logopt, int logfac)
{
  char *progname;
  
  progname = (progname = strrchr((*argv)[0], '/')) ? progname+1 : (*argv)[0];
  openlog(progname, logopt, logfac);
}

void
log_raw(int priority, const char *format, ...)
{
  char *prefix;
  FILE *out;
  va_list args;

  out=stderr;
  switch (priority) {
    case LOG_EMERG:
      prefix="<EMERG>";
      break;
    case LOG_ALERT:
      prefix="<ALERT>";
      break;
    case LOG_ERR:
      prefix="<ERR>  ";
      break;
    case LOG_WARNING:
      prefix="<WARN> ";
      break;
    case LOG_NOTICE:
      prefix="<NOTE> ";
      out=stdout;
      break;
    case LOG_INFO:
      prefix="<INFO> ";
      out=stdout;
      break;
    case LOG_DEBUG:
      prefix="<DEBUG>";
      out=stdout;
      break;
    default:
      prefix="<INFO> ";
      out=stdout;
  }

  va_start(args, format);
  vsyslog(priority, format, args);
  va_end(args);

  if (out) {
    va_start(args, format);
    (void)fprintf(out, "%s ", prefix);
    (void)vfprintf(out, format, args);
    if (format[strlen(format) - 1] != '\n') {
        (void)fprintf(out, "\n");
    }
    va_end(args);
  }
}

{'fraction_non_alphanumeric': 0.16594059405940595, 'fraction_numerical': 0.002772277227722772, 'mean_word_length': 2.6555716353111434, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '4051252', 'n_tokens_mistral': 965, 'n_tokens_neox': 947, 'n_words': 206}