<commit_before>#pragma once

#include "syslog.h"

#include <string>

#include "blackhole/error.hpp"
#include "blackhole/repository/factory/traits.hpp"

namespace blackhole {

namespace sink {

enum class priority_t : unsigned {
    emerg   = LOG_EMERG,
    alert   = LOG_ALERT,
    crit    = LOG_CRIT,
    err     = LOG_ERR,
    warning = LOG_WARNING,
    notice  = LOG_NOTICE,
    info    = LOG_INFO,
    debug   = LOG_DEBUG
};

template<typename Level>
struct priority_traits;

namespace backend {

class native_t {
    const std::string m_identity;
public:
    native_t(const std::string& identity, int option = LOG_PID, int facility = LOG_USER) :
        m_identity(identity)
    {
        initialize(option, facility);
    }

    ~native_t() {
        ::closelog();
    }

    void write(priority_t priority, const std::string& message) {
        ::syslog(static_cast<unsigned>(priority), "%s", message.c_str());
    }

private:
    void initialize(int option, int facility) {
        if (m_identity.empty()) {
            throw error_t("no syslog identity has been specified");
        }

        ::openlog(m_identity.c_str(), option, facility);
    }
};

} // namespace backend

namespace syslog {

struct config_t {
    std::string identity;
    int option;
    int facility;

    config_t() {}

    config_t(const std::string& identity, int option = LOG_PID, int facility = LOG_USER) :
        identity(identity),
        option(option),
        facility(facility)
    {}

    config_t(const std::string& identity, int facility) :
        identity(identity),
        option(LOG_PID),
        facility(facility)
    {}
};

} // namespace syslog

template<typename Level, typename Backend = backend::native_t>
class syslog_t {
    Backend m_backend;

public:
    typedef syslog::config_t config_type;

    static const char* name() {
        return "syslog";
    }
<commit_msg>[Bug Fix] Fixed undefined behaviour.<commit_after>#pragma once

#include "syslog.h"

#include <string>

#include "blackhole/error.hpp"
#include "blackhole/repository/factory/traits.hpp"

namespace blackhole {

namespace sink {

enum class priority_t : unsigned {
    emerg   = LOG_EMERG,
    alert   = LOG_ALERT,
    crit    = LOG_CRIT,
    err     = LOG_ERR,
    warning = LOG_WARNING,
    notice  = LOG_NOTICE,
    info    = LOG_INFO,
    debug   = LOG_DEBUG
};

template<typename Level>
struct priority_traits;

namespace backend {

class native_t {
    const std::string m_identity;

public:
    native_t(const std::string& identity, int option = LOG_PID, int facility = LOG_USER) :
        m_identity(identity)
    {
        initialize(option, facility);
    }

    ~native_t() {
        ::closelog();
    }

    void write(priority_t priority, const std::string& message) {
        ::syslog(static_cast<unsigned>(priority), "%s", message.c_str());
    }

private:
    void initialize(int option, int facility) {
        if (m_identity.empty()) {
            throw error_t("no syslog identity has been specified");
        }

        ::openlog(m_identity.c_str(), option, facility);
    }
};

} // namespace backend

namespace syslog {

struct config_t {
    std::string identity;
    int option;
    int facility;

    config_t() :
        identity("blackhole"),
        option(LOG_PID),
        facility(LOG_USER)
    {}

    config_t(const std::string& identity, int option = LOG_PID, int facility = LOG_USER) :
        identity(identity),
        option(option),
        facility(facility)
    {}

    config_t(const std::string& identity, int facility) :
        identity(identity),
        option(LOG_PID),
        facility(facility)
    {}
};

} // namespace syslog

template<typename Level, typename Backend = backend::native_t>
class syslog_t {
    Backend m_backend;

public:
    typedef syslog::config_t config_type;

    static const char* name() {
        return "syslog";
    }

{'fraction_non_alphanumeric': 0.11285751095078587, 'fraction_numerical': 0.0, 'mean_word_length': 2.8397626112759644, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7531905', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1203, 'n_words': 289}