<commit_before>/**
 =========================================================================================
 File name	: /httpico/include/Logger.cpp
 Copyright	: Copyright © 2012 <NAME>, Licensed under the Apache License, Version 2.0
 =========================================================================================
 */

#include "Logger.hpp"
#include "HttpServerConfiguration.hpp"
#include <csignal>
#include <cstdarg>
#include <cstdio>
#include <iostream>
#include <ctime>
#include <sstream>
#include "Utils.hpp"

namespace Httpico {

namespace { //unnamed namespace
void logToFile(FILE *f, const char *fmt, va_list args, const char *prefix) {
	std::ostringstream out;
	out << prefix << " (" << Utils::getTimestamp() << ", TID: " << pthread_self() << "): " << fmt;
	vfprintf(f, out.str().c_str(), args);
	fflush(f);
}

} //namespace

Logger *Logger::instance = NULL;

void Logger::fallbackLog(const char *fmt, ...) {
	va_list args;
	va_start(args, fmt);
	logToFile(stderr, fmt, args, "FATAL ERROR");
	va_end(args);
}

void Logger::log(const char *fmt, ...) {
	va_list args;
	va_start(args, fmt);
	logToFile(stdout, fmt, args, "INFO");
	if (logFile != NULL) {
		va_start(args, fmt);
		logToFile(logFile, fmt, args, "INFO");
		va_end(args);
	}
}

void Logger::dbg(const char *fmt, ...) {
	return; //todo
	va_list args;
	va_start(args, fmt);
	logToFile(stderr, fmt, args, "DEBUG");
	va_end(args);
	if (logFile != NULL) {
		va_start(args, fmt);
		logToFile(logFile, fmt, args, "DEBUG");
		va_end(args);
	}
}

Logger &Logger::getInstance() {
	return *instance;
}

Logger::Logger(HttpServerConfiguration &c) :
		logFile(NULL), conf(c) {
	if (instance != NULL) {
		delete instance;
	}
	std::string logFileName = conf.getLoggingFolder() + "/httpico_" + Utils::getTimestamp() + ".log";

	logFile = fopen(logFileName.c_str(), "w");
	if (logFile == NULL) {
		Logger::fallbackLog("Couldn't open logging file\n");
	}

	instance = this;
}

Logger::~Logger() {
	fclose(logFile);
}

} //namespace Httpico
<commit_msg>Removed thread information from logger<commit_after>/**
 =========================================================================================
 File name	: /httpico/include/Logger.cpp
 Copyright	: Copyright © 2012 <NAME>, Licensed under the Apache License, Version 2.0
 =========================================================================================
 */

#include "Logger.hpp"
#include "HttpServerConfiguration.hpp"
#include <csignal>
#include <cstdarg>
#include <cstdio>
#include <iostream>
#include <ctime>
#include <sstream>
#include "Utils.hpp"

namespace Httpico {

namespace { //unnamed namespace
void logToFile(FILE *f, const char *fmt, va_list args, const char *prefix) {
	std::ostringstream out;
	out << prefix << " (" << Utils::getTimestamp() << "): " << fmt;
	vfprintf(f, out.str().c_str(), args);
	fflush(f);
}

} //namespace

Logger *Logger::instance = NULL;

void Logger::fallbackLog(const char *fmt, ...) {
	va_list args;
	va_start(args, fmt);
	logToFile(stderr, fmt, args, "FATAL ERROR");
	va_end(args);
}

void Logger::log(const char *fmt, ...) {
	va_list args;
	va_start(args, fmt);
	logToFile(stdout, fmt, args, "INFO");
	if (logFile != NULL) {
		va_start(args, fmt);
		logToFile(logFile, fmt, args, "INFO");
		va_end(args);
	}
}

void Logger::dbg(const char *fmt, ...) {
	return; //todo
	va_list args;
	va_start(args, fmt);
	logToFile(stderr, fmt, args, "DEBUG");
	va_end(args);
	if (logFile != NULL) {
		va_start(args, fmt);
		logToFile(logFile, fmt, args, "DEBUG");
		va_end(args);
	}
}

Logger &Logger::getInstance() {
	return *instance;
}

Logger::Logger(HttpServerConfiguration &c) :
		logFile(NULL), conf(c) {
	if (instance != NULL) {
		delete instance;
	}
	std::string logFileName = conf.getLoggingFolder() + "/httpico_" + Utils::getTimestamp() + ".log";

	logFile = fopen(logFileName.c_str(), "w");
	if (logFile == NULL) {
		Logger::fallbackLog("Couldn't open logging file\n");
	}

	instance = this;
}

Logger::~Logger() {
	fclose(logFile);
}

} //namespace Httpico

{'fraction_non_alphanumeric': 0.25161611138736945, 'fraction_numerical': 0.0029835902536051715, 'mean_word_length': 5.27613104524181, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 17, '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': '78894', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1363, 'n_words': 326}