<commit_before>#ifndef MJOLNIR_UTIL_LOGGER_HPP
#define MJOLNIR_UTIL_LOGGER_HPP
#include <mjolnir/util/macro.hpp>
#include <mjolnir/util/make_unique.hpp>
#include <mjolnir/util/throw_exception.hpp>
#include <mjolnir/util/color.hpp>
#include <mjolnir/util/range.hpp>
#include <array>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <chrono>

namespace mjolnir
{

/* these macros are defined.                                                 *
 * - MJOLNIR_LOG_DEBUG  -- for debugging. it makes simulation too slow.      *
 * - MJOLNIR_LOG_INFO   -- output in-detail info unless it slows down.       *
 * - MJOLNIR_LOG_NOTICE -- write current progress and status to console.     *
 * - MJOLNIR_LOG_WARN   -- may not be wrong, but undesirable stuff happens.  *
 * - MJOLNIR_LOG_ERROR  -- something wrong.                                  *
 *                                                                           *
 * - MJOLNIR_LOG_SCOPE    -- helps logging by indentation.                   *
 * - MJOLNIR_LOG_FUNCTION -- helps logging by indentation.                   *
 *
 * - MJOLNIR_GET_LOGGER -- get a logger for the current scope with name.     *
 * - MJOLNIR_GET_DEFAULT_LOGGER -- get a default logger.                     */

namespace logger_detail
{
// since there is no standard way to format containers, the standard library
// does not provide output operators for containers. To make logging easier,
// here output operators are defined for some of the containers.
// To avoid fixing the output format, these are defined in the special namespace
// `logger_detail`. loggers first imports this namespace and output using these
// operators.

template<typename charT, typename traits, typename Iterator>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const range<Iterator>& rg)
{
    os << '[';
    for(const auto& v : rg){os << v << ", ";}
    os << ']';
    return os;
}

template<typename charT, typename traits, typename T, std::size_t N>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const std::array<T, N>& ar)
{
    os << '[';
    for(const auto& v : ar){os << v << ", ";}
    os << ']';
    return os;
}

template<typename charT, typename traits, typename T, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
           const std::vector<T, Alloc>& vc)
{
    os << '[';
    for(const auto item : vc){os << item << ", ";}
    os << ']';
    return os;
}

template<typename charT, typename traits, typename Key, typename Value,
         typename Comp, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
           const std::map<Key, Value, Comp, Alloc>& mp)
{
    os << '{';
    for(const auto kv : mp){os << kv.first << '=' << kv.second << ", ";}
    os << '}';
    return os;
}

template<typename charT, typename traits, typename Key, typename Value,
         typename Hash, typename Pred, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
           const std::unordered_map<Key, Value, Hash, Pred, Alloc>& mp)
{
    os << '{';
    for(const auto kv : mp){os << kv.first << '=' << kv.second << ", ";}
    os << '}';
    return os;
}<commit_msg>refactor: add reference to auto<commit_after>#ifndef MJOLNIR_UTIL_LOGGER_HPP
#define MJOLNIR_UTIL_LOGGER_HPP
#include <mjolnir/util/macro.hpp>
#include <mjolnir/util/make_unique.hpp>
#include <mjolnir/util/throw_exception.hpp>
#include <mjolnir/util/color.hpp>
#include <mjolnir/util/range.hpp>
#include <array>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <chrono>

namespace mjolnir
{

/* these macros are defined.                                                 *
 * - MJOLNIR_LOG_DEBUG  -- for debugging. it makes simulation too slow.      *
 * - MJOLNIR_LOG_INFO   -- output in-detail info unless it slows down.       *
 * - MJOLNIR_LOG_NOTICE -- write current progress and status to console.     *
 * - MJOLNIR_LOG_WARN   -- may not be wrong, but undesirable stuff happens.  *
 * - MJOLNIR_LOG_ERROR  -- something wrong.                                  *
 *                                                                           *
 * - MJOLNIR_LOG_SCOPE    -- helps logging by indentation.                   *
 * - MJOLNIR_LOG_FUNCTION -- helps logging by indentation.                   *
 *
 * - MJOLNIR_GET_LOGGER -- get a logger for the current scope with name.     *
 * - MJOLNIR_GET_DEFAULT_LOGGER -- get a default logger.                     */

namespace logger_detail
{
// since there is no standard way to format containers, the standard library
// does not provide output operators for containers. To make logging easier,
// here output operators are defined for some of the containers.
// To avoid fixing the output format, these are defined in the special namespace
// `logger_detail`. loggers first imports this namespace and output using these
// operators.

template<typename charT, typename traits, typename Iterator>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const range<Iterator>& rg)
{
    os << '[';
    for(const auto& v : rg){os << v << ", ";}
    os << ']';
    return os;
}

template<typename charT, typename traits, typename T, std::size_t N>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const std::array<T, N>& ar)
{
    os << '[';
    for(const auto& v : ar){os << v << ", ";}
    os << ']';
    return os;
}

template<typename charT, typename traits, typename T, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
           const std::vector<T, Alloc>& vc)
{
    os << '[';
    for(const auto& item : vc){os << item << ", ";}
    os << ']';
    return os;
}

template<typename charT, typename traits, typename Key, typename Value,
         typename Comp, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
           const std::map<Key, Value, Comp, Alloc>& mp)
{
    os << '{';
    for(const auto& kv : mp){os << kv.first << '=' << kv.second << ", ";}
    os << '}';
    return os;
}

template<typename charT, typename traits, typename Key, typename Value,
         typename Hash, typename Pred, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
           const std::unordered_map<Key, Value, Hash, Pred, Alloc>& mp)
{
    os << '{';
    for(const auto& kv : mp){os << kv.first << '=' << kv.second << ", ";}
    os << '}';
    return os;
}
{'fraction_non_alphanumeric': 0.13536032743750914, 'fraction_numerical': 0.0, 'mean_word_length': 2.8808848553601814, 'pattern_counts': {'":': 0, '<': 189, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '82206', 'n_tokens_mistral': 2206, 'n_tokens_neox': 2124, 'n_words': 612}