<commit_before>////////////////////////////////////////////////////////////
//
// DAGON - An Adventure Game Engine
// Copyright (c) 2011-2013 Senscape s.r.l.
// All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
//
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////

#include <cstdarg>
#include <iostream>

#include "Config.h"
#include "Log.h"
#include "DGObject.h"

////////////////////////////////////////////////////////////
// Implementation - Constructor
////////////////////////////////////////////////////////////

Log::Log() :
  config(Config::instance()) {
}

////////////////////////////////////////////////////////////
// Implementation - Destructor
////////////////////////////////////////////////////////////

Log::~Log() {
  if (_filestr.is_open())
    _filestr.close();
}

////////////////////////////////////////////////////////////
// Implementation
////////////////////////////////////////////////////////////

void Log::command(int forModule, const char* theString, ...) {
  char buffer[256];
  va_list args;
  
  va_start(args, theString);
  vsprintf(buffer, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorBrightMagenta;
	data.module = forModule;
	data.type = kLogTrace;
	
	_log(&data);
}

void Log::error(int forModule, const char* theString, ...) {
  char buffer[256];
  va_list args;
  
  va_start(args, theString);
  vsprintf(buffer, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorBrightRed;
	data.module = forModule;
	data.type = kLogError;
	
	_log(&data); 
}

void Log::info(int forModule, const char* theString, ...) {
  char buffer[256];
  va_list args;
  
  va_start(args, theString);
  vsprintf(buffer, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorBrightCyan;
	data.module = forModule;
	data.type = kLogTrace;
	
	_log(&data);
}

void Log::trace(int forModule, const char* theString, ...) {
  char buffer[256];
  va_list args;
  
  va_start(args, theString);
  vsprintf(buffer, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorWhite;
	data.module = forModule;
	data.type = kLogTrace;
	
	_log(&data); 
}

void Log::warning(int forModule, const char* theString, ...) {
  char buffer[256];
  va_list args;
  
  va_start(args, theString);
  vsprintf(buffer, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorYellow;<commit_msg>Safer logging with vsnprintf().<commit_after>////////////////////////////////////////////////////////////
//
// DAGON - An Adventure Game Engine
// Copyright (c) 2011-2013 Senscape s.r.l.
// All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
//
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////

#include <cstdarg>
#include <iostream>

#include "Config.h"
#include "Log.h"
#include "DGObject.h"

////////////////////////////////////////////////////////////
// Implementation - Constructor
////////////////////////////////////////////////////////////

Log::Log() :
  config(Config::instance()) {
}

////////////////////////////////////////////////////////////
// Implementation - Destructor
////////////////////////////////////////////////////////////

Log::~Log() {
  if (_filestr.is_open())
    _filestr.close();
}

////////////////////////////////////////////////////////////
// Implementation
////////////////////////////////////////////////////////////

void Log::command(int forModule, const char* theString, ...) {
  char buffer[kMaxLogLength];
  va_list args;
  
  va_start(args, theString);
  vsnprintf(buffer, kMaxLogLength, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorBrightMagenta;
	data.module = forModule;
	data.type = kLogTrace;
	
	_log(&data);
}

void Log::error(int forModule, const char* theString, ...) {
  char buffer[kMaxLogLength];
  va_list args;
  
  va_start(args, theString);
  vsnprintf(buffer, kMaxLogLength, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorBrightRed;
	data.module = forModule;
	data.type = kLogError;
	
	_log(&data); 
}

void Log::info(int forModule, const char* theString, ...) {
  char buffer[kMaxLogLength];
  va_list args;
  
  va_start(args, theString);
  vsnprintf(buffer, kMaxLogLength, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorBrightCyan;
	data.module = forModule;
	data.type = kLogTrace;
	
	_log(&data);
}

void Log::trace(int forModule, const char* theString, ...) {
  char buffer[kMaxLogLength];
  va_list args;
  
  va_start(args, theString);
  vsnprintf(buffer, kMaxLogLength, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorWhite;
	data.module = forModule;
	data.type = kLogTrace;
	
	_log(&data); 
}

void Log::warning(int forModule, const char* theString, ...) {
  char buffer[kMaxLogLength];
  va_list args;
  
  va_start(args, theString);
  vsnprintf(buffer, kMaxLogLength, theString, args);
  va_end(args);
	
  LogData data;
  
  data.line = buffer;
	data.color = kColorYellow;
{'fraction_non_alphanumeric': 0.3177892918825561, 'fraction_numerical': 0.006735751295336788, 'mean_word_length': 1.6085585585585584, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6459759', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1708, 'n_words': 407}