<commit_before>#include <blackhole/log.hpp>
#include <blackhole/repository.hpp>

using namespace blackhole;

enum class level {
    debug,
    info,
    warning,
    error
};

namespace blackhole { namespace sink {

template<>
struct priority_traits<level> {
    static inline
    priority_t map(level lvl) {
        switch (lvl) {
        case level::debug:
            return priority_t::debug;
        case level::info:
            return priority_t::info;
        case level::warning:
            return priority_t::warning;
        case level::error:
            return priority_t::err;
        }

        return priority_t::debug;
    }
};

} } // namespace blackhole::sink


//! Initialization stage.
//! \brief Manually or from file - whatever. The main aim - is to get initialized `log_config_t` object.
/*! Formatter config looks like:
 *  {
 *      "json": {
 *          "newline": true,
 *          "mapping": {
 *              "naming": {
 *                  "message": "@message"
 *              },
 *              "positioning": {
 *                  "/": ["message"],
 *                  "/fields": "*"
 *              }
 *          }
 *      }
 *  }
 */
void init() {
    formatter_config_t formatter = {
        "json",
        boost::any {
            std::vector<boost::any> {
                true,
                std::unordered_map<std::string, std::string> { { "message", "@message" } },
                std::unordered_map<std::string, boost::any> {
                    { "/", std::vector<std::string> { "message" } },
                    { "/fields", std::string("*") }
                }
            }
        }
    };

    sink_config_t sink = {
        "socket",
        std::map<std::string, std::string>{
            { "type", "tcp" },
            { "host", "localhost" },
            { "port", "50030" }
        }
    };

    frontend_config_t frontend = { formatter, sink };
    log_config_t config{ "root", { frontend } };<commit_msg>More comments with logstash example.<commit_after>#include <blackhole/log.hpp>
#include <blackhole/repository.hpp>

using namespace blackhole;

//! Our logger severity enumeration.
enum class level {
    debug,
    info,
    warning,
    error
};

namespace blackhole { namespace sink {

//! Priority mapping function overload for proper syslog mapping.
template<>
struct priority_traits<level> {
    static inline
    priority_t map(level lvl) {
        switch (lvl) {
        case level::debug:
            return priority_t::debug;
        case level::info:
            return priority_t::info;
        case level::warning:
            return priority_t::warning;
        case level::error:
            return priority_t::err;
        }

        return priority_t::debug;
    }
};

} } // namespace blackhole::sink


//! Initialization stage.
//! \brief Manually or from file - whatever. The main aim - is to get initialized `log_config_t` object.
//! For logstash we need log object which sends json-packed messages through tcp socket.
/*! Formatter config looks like:
 *  "formatter": {
 *      "json": {
 *          "newline": true,
 *          "mapping": {
 *              "naming": {
 *                  "message": "@message",
 *                  "timestamp": "@timestamp"
 *              },
 *              "positioning": {
 *                  "/": ["@message", "@timestamp"],
 *                  "/fields": "*"
 *              }
 *          }
 *      }
 *  }
 *
 *  Sink config can be:
 *  "sink": {
 *      "socket": {
 *          "type": "tcp",
 *          "host": "localhost",
 *          "port": 50030
 *      }
 *  }
 */
void init() {
    formatter_config_t formatter = {
        "json",
        boost::any {
            std::vector<boost::any> {
                true,
                std::unordered_map<std::string, std::string> {
                    { "message", "@message" },
                    { "timestamp", "@timestamp" }
                },
                std::unordered_map<std::string, boost::any> {
                    { "/", std::vector<std::string> { "@message", "@timestamp" } },
                    { "/fields", std::string("*") }
                }
            }
        }
    };

    sink_config_t sink = {
        "socket",
        std::map<std::string, std::string>{
            { "type", "tcp" },
            { "host", "localhost" },
            { "port", "50030" }
        }
    };

    frontend_config_t frontend = { formatter, sink };
    log_config_t config{ "root", { frontend } };
{'fraction_non_alphanumeric': 0.14738015607580826, 'fraction_numerical': 0.0033444816053511705, 'mean_word_length': 1.6233918128654972, 'pattern_counts': {'":': 23, '<': 21, '<?xml version=': 0, '>': 21, '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': '7034344', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1264, 'n_words': 280}