<commit_before>/* Buzz Machine Loader
 * Copyright (C) 2006 Buzztrax team <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

/* we can configure the packge with --enable-debug to get LOG defined
 * if log is defined logging is compiled in otherwise out
 * if it is in we can still control the amount of logging by setting bits in
 * BML_DEBUG:
 *   1 : only logging from the windows adapter (BuzzMachineLoader.dll)
 *   2 : only logging from bml and dllwrapper
 */

#include <sys/time.h>
#include <time.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#include "bmllog.h"

static double _first_ts = 0.0;

static double
_get_timestamp (void)
{
  struct timespec ts;

  clock_gettime(CLOCK_MONOTONIC, &ts);
  return (((double) ts.tv_sec+ (double) ts.tv_nsec * 1.0e-9) - _first_ts);
}

static void
_log_stdout_printf (const char *file, const int line, const char *func, const char *fmt, ...)
{
  va_list ap;
  char msg[4000];

  va_start(ap, fmt);
  vsnprintf (msg, 4000, fmt, ap);
  va_end(ap);
  msg[3999]='\0';
  fprintf (stderr, "%10.4lf: %s:%d:%s: %s", _get_timestamp(), (file?file:""), line, (func?func:""), msg);
}

static void
_log_null_printf (const char *file, const int line, const char *func, const char *fmt, ...)
{
}

// name is also used in dllwrapper/debugtools.h
BmlLogger _log_printf = _log_null_printf;

// collect lines up to 1000 chars
static void _log_stdout_logger(char *str) {
#ifdef LOG
  static char lbuf[1000];<commit_msg>bmllog: use our configure checks for clock_gettime<commit_after>/* Buzz Machine Loader
 * Copyright (C) 2006 Buzztrax team <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

/* we can configure the packge with --enable-debug to get LOG defined
 * if log is defined logging is compiled in otherwise out
 * if it is in we can still control the amount of logging by setting bits in
 * BML_DEBUG:
 *   1 : only logging from the windows adapter (BuzzMachineLoader.dll)
 *   2 : only logging from bml and dllwrapper
 */

#include "config.h"

#include <sys/time.h>
#include <time.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#include "bmllog.h"

static double _first_ts = 0.0;

static double
_get_timestamp (void)
{
#ifdef HAVE_CLOCK_GETTIME
  struct timespec ts;

  clock_gettime(CLOCK_MONOTONIC, &ts);
  return (((double) ts.tv_sec + (double) ts.tv_nsec * 1.0e-9) - _first_ts);
#else
  struct timeval ts;

  gettimeofday (&ts, NULL);
  return (((double) ts.tv_sec + (double) ts.tv_usec * 1.0e-6) -  _first_ts);
#endif
}

static void
_log_stdout_printf (const char *file, const int line, const char *func, const char *fmt, ...)
{
  va_list ap;
  char msg[4000];

  va_start(ap, fmt);
  vsnprintf (msg, 4000, fmt, ap);
  va_end(ap);
  msg[3999]='\0';
  fprintf (stderr, "%10.4lf: %s:%d:%s: %s", _get_timestamp(), (file?file:""), line, (func?func:""), msg);
}

static void
_log_null_printf (const char *file, const int line, const char *func, const char *fmt, ...)
{
}

// name is also used in dllwrapper/debugtools.h
BmlLogger _log_printf = _log_null_printf;

// collect lines up to 1000 chars
static void _log_stdout_logger(char *str) {
#ifdef LOG
  static char lbuf[1000];
{'fraction_non_alphanumeric': 0.10867104369481549, 'fraction_numerical': 0.01697985057731492, 'mean_word_length': 4.026166097838453, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '449491', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1406, 'n_words': 572}