<commit_before>#ifndef LOGGER_H
#define LOGGER_H

#include <string>
#include <fstream>
#include <sstream>
#include <ostream>
#include <vector>
#include <map>
#include <typeinfo>

#include "general.h"
#include "exception.h"
#include "xstring.h"

// default shows it all
// (set this before you include xlogger.h)
#ifndef XLOG_MIN_LOG_LVL
#define XLOG_MIN_LOG_LVL 1
#endif

// This is the main #DEFINE - do not change!
#define LOG(lvl, LOGID)                                                 \
  if (TOOLS::XLogger::check_loglevel(lvl, LOGID))                       \
  TOOLS::LogStream(TOOLS::XLogger::get(LOGID), lvl, __LINE__, __FILE__, \
                   __FUNCTION__)

#define FAKELOG() TOOLS::FakeLogStream()

// Some ready-to-use examples for special loggers
// all can be used like this:
// WARN << "my message goes here" << "another one" << 123 << " and add
// formatting";

#if XLOG_MIN_LOG_LVL <= 1
#define MAX_LOG LOG(1, LOGID)
#define IS_MAX_LOG true
#else
#define MAX_LOG FAKELOG()
#define IS_MAX_LOG false
#endif

#if XLOG_MIN_LOG_LVL <= 2
#define MORE_DEBUG LOG(2, LOGID)
#define IS_MORE_DEBUG true
#else
#define MORE_DEBUG FAKELOG()
#define IS_MORE_DEBUG false
#endif

#if XLOG_MIN_LOG_LVL <= 3
#define DEBUG LOG(3, LOGID)
#define IS_DEBUG true
#else
#define DEBUG FAKELOG()
#define IS_DEBUG false
#endif

#if XLOG_MIN_LOG_LVL <= 5
#define INFO LOG(5, LOGID)
#define IS_INFO true
#else
#define INFO FAKELOG()
#define IS_INFO false
#endif

#if XLOG_MIN_LOG_LVL <= 7
#define WARN LOG(7, LOGID)
#define IS_WARN true
#else
#define WARN FAKELOG()
#define IS_WARN false
#endif

#if XLOG_MIN_LOG_LVL <= 10
#define ERROR LOG(10, LOGID)
#define IS_ERROR true
#else
#define ERROR FAKELOG()
#define IS_ERROR false
#endif

namespace TOOLS {

DEFINE_EXCEPTION(BackendFailedToWrite, BaseException)
DEFINE_EXCEPTION(NoSuchXLoggerAvailable, BaseException)
DEFINE_EXCEPTION(NoSuchBackendAvailable, BaseException)
DEFINE_EXCEPTION(NoMessageProvided, BaseException)
DEFINE_EXCEPTION(LoggerIDAlreadyRegistered, BaseException)

class XLogger;

typedef std::map<std::string, XLogger*> tXLoggerMap;

class BaseLoggerBackend {
 public:
  std::string id;
  std::string name;

  BaseLoggerBackend(const std::string& my_id, const std::string& my_name);
  virtual ~BaseLoggerBackend();

  virtual void write(const std::string& text) = 0;
  virtual void init();
  virtual void cleanup();
};

class FileBackend : public BaseLoggerBackend {
 public:
  std::string filename;<commit_msg>logger define fixes<commit_after>#ifndef LOGGER_H
#define LOGGER_H

#include <string>
#include <fstream>
#include <sstream>
#include <ostream>
#include <vector>
#include <map>
#include <typeinfo>

#include "general.h"
#include "exception.h"
#include "xstring.h"

// default shows it all
// (set this before you include xlogger.h)
#ifndef XLOG_MIN_LOG_LVL
#define XLOG_MIN_LOG_LVL 1
#endif

// This is the main #DEFINE - do not change!
#define LOG(lvl, LOGID)                                                 \
  if (TOOLS::XLogger::check_loglevel(lvl, LOGID))                       \
  TOOLS::LogStream(TOOLS::XLogger::get(LOGID), lvl, __LINE__, __FILE__, \
                   __FUNCTION__)

#define FAKELOG() TOOLS::FakeLogStream()

// Some ready-to-use examples for special loggers
// all can be used like this:
// WARN << "my message goes here" << "another one" << 123 << " and add
// formatting";

#if XLOG_MIN_LOG_LVL <= 1
#define MAX_LOG LOG(1, LOGID)
#define IS_MAX_LOG true && TOOLS::XLogger::check_loglevel(1, LOGID)
#else
#define MAX_LOG if(false) FAKELOG() 
#define IS_MAX_LOG false
#endif

#if XLOG_MIN_LOG_LVL <= 2
#define MORE_DEBUG LOG(2, LOGID)
#define IS_MORE_DEBUG true && TOOLS::XLogger::check_loglevel(2, LOGID)
#else
#define MORE_DEBUG if(false) FAKELOG()
#define IS_MORE_DEBUG false
#endif

#if XLOG_MIN_LOG_LVL <= 3
#define DEBUG LOG(3, LOGID)
#define IS_DEBUG true && TOOLS::XLogger::check_loglevel(3, LOGID)
#else
#define DEBUG if(false) FAKELOG()
#define IS_DEBUG false
#endif

#if XLOG_MIN_LOG_LVL <= 5
#define INFO LOG(5, LOGID)
#define IS_INFO true && TOOLS::XLogger::check_loglevel(4, LOGID)
#else
#define INFO if(false) FAKELOG()
#define IS_INFO false
#endif

#if XLOG_MIN_LOG_LVL <= 7
#define WARN LOG(7, LOGID)
#define IS_WARN true && TOOLS::XLogger::check_loglevel(7, LOGID)
#else
#define WARN if(false) FAKELOG()
#define IS_WARN false
#endif

#if XLOG_MIN_LOG_LVL <= 10
#define ERROR LOG(10, LOGID)
#define IS_ERROR true && TOOLS::XLogger::check_loglevel(10, LOGID)
#else
#define ERROR if(false) FAKELOG()
#define IS_ERROR false
#endif

namespace TOOLS {

DEFINE_EXCEPTION(BackendFailedToWrite, BaseException)
DEFINE_EXCEPTION(NoSuchXLoggerAvailable, BaseException)
DEFINE_EXCEPTION(NoSuchBackendAvailable, BaseException)
DEFINE_EXCEPTION(NoMessageProvided, BaseException)
DEFINE_EXCEPTION(LoggerIDAlreadyRegistered, BaseException)

class XLogger;

typedef std::map<std::string, XLogger*> tXLoggerMap;

class BaseLoggerBackend {
 public:
  std::string id;
  std::string name;

  BaseLoggerBackend(const std::string& my_id, const std::string& my_name);
  virtual ~BaseLoggerBackend();

  virtual void write(const std::string& text) = 0;
  virtual void init();
  virtual void cleanup();
};

class FileBackend : public BaseLoggerBackend {
 public:
  std::string filename;
{'fraction_non_alphanumeric': 0.11456752655538695, 'fraction_numerical': 0.00853566009104704, 'mean_word_length': 4.978458049886621, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4758485', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1846, 'n_words': 509}