<commit_before>/***************************************************************************
                          hierarchy.cpp  -  description
                             -------------------
    begin                : jeu avr 17 2003
    copyright            : (C) 2003 by <NAME>
    email                : <EMAIL>
 ***************************************************************************/

/***************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights reserved.      *
 *                                                                         *
 * This software is published under the terms of the Apache Software       *
 * License version 1.1, a copy of which has been included with this        *
 * distribution in the LICENSE.txt file.                                   *
 ***************************************************************************/

#include <log4cxx/spi/loggerfactory.h>
#include <log4cxx/hierarchy.h>
#include <log4cxx/defaultcategoryfactory.h>
#include <log4cxx/logger.h>
#include <log4cxx/spi/hierarchyeventlistener.h>
#include <log4cxx/level.h>
#include <algorithm>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/appender.h>

using namespace log4cxx;
using namespace log4cxx::spi;
using namespace log4cxx::helpers;

IMPLEMENT_LOG4CXX_OBJECT(Hierarchy)

namespace {
    bool startsWith(const String& teststr, const String& substr)
	{
        bool val = false;
        if(teststr.length() > substr.length()) {
            val = teststr.substr(0, substr.length()) == substr;
        }

        return val;
    }
}

Hierarchy::Hierarchy(LoggerPtr root) : root(root),
emittedNoAppenderWarning(false), emittedNoResourceBundleWarning(false)
{
	// Enable all level levels by default.
	setThreshold(Level::ALL);
	this->root->setHierarchy(this);
	defaultFactory = new DefaultCategoryFactory();
}

Hierarchy::~Hierarchy()
{
}

void Hierarchy::addHierarchyEventListener(spi::HierarchyEventListenerPtr listener)
{
	if (std::find(listeners.begin(), listeners.end(), listener) != listeners.end())
	{
		LogLog::warn(_T("Ignoring attempt to add an existent listener."));
	} 
	else
	{
		listeners.push_back(listener);
	}
}

void Hierarchy::clear()
{
	mapCs.lock();

	loggers.clear();
	
	mapCs.unlock();
}

void Hierarchy::emitNoAppenderWarning(LoggerPtr logger)
{
	// No appenders in hierarchy, warn user only once.
	if(!this->emittedNoAppenderWarning)
	{
		LogLog::warn(_T("No appenders could be found for logger (") +<commit_msg>changed passing parameter by value to passing parameter by reference<commit_after>/***************************************************************************
                          hierarchy.cpp  -  description
                             -------------------
    begin                : jeu avr 17 2003
    copyright            : (C) 2003 by <NAME>
    email                : <EMAIL>
 ***************************************************************************/

/***************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights reserved.      *
 *                                                                         *
 * This software is published under the terms of the Apache Software       *
 * License version 1.1, a copy of which has been included with this        *
 * distribution in the LICENSE.txt file.                                   *
 ***************************************************************************/

#include <log4cxx/spi/loggerfactory.h>
#include <log4cxx/hierarchy.h>
#include <log4cxx/defaultcategoryfactory.h>
#include <log4cxx/logger.h>
#include <log4cxx/spi/hierarchyeventlistener.h>
#include <log4cxx/level.h>
#include <algorithm>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/appender.h>

using namespace log4cxx;
using namespace log4cxx::spi;
using namespace log4cxx::helpers;

IMPLEMENT_LOG4CXX_OBJECT(Hierarchy)

namespace {
    bool startsWith(const String& teststr, const String& substr)
	{
        bool val = false;
        if(teststr.length() > substr.length()) {
            val = teststr.substr(0, substr.length()) == substr;
        }

        return val;
    }
}

Hierarchy::Hierarchy(LoggerPtr root) : root(root),
emittedNoAppenderWarning(false), emittedNoResourceBundleWarning(false)
{
	// Enable all level levels by default.
	setThreshold(Level::ALL);
	this->root->setHierarchy(this);
	defaultFactory = new DefaultCategoryFactory();
}

Hierarchy::~Hierarchy()
{
}

void Hierarchy::addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener)
{
	if (std::find(listeners.begin(), listeners.end(), listener) != listeners.end())
	{
		LogLog::warn(_T("Ignoring attempt to add an existent listener."));
	} 
	else
	{
		listeners.push_back(listener);
	}
}

void Hierarchy::clear()
{
	mapCs.lock();

	loggers.clear();
	
	mapCs.unlock();
}

void Hierarchy::emitNoAppenderWarning(LoggerPtr logger)
{
	// No appenders in hierarchy, warn user only once.
	if(!this->emittedNoAppenderWarning)
	{
		LogLog::warn(_T("No appenders could be found for logger (") +
{'fraction_non_alphanumeric': 0.2232839313572543, 'fraction_numerical': 0.009750390015600624, 'mean_word_length': 3.193785772690106, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1602111', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1386, 'n_words': 324}