<commit_before>#pragma once
#include "xyz/openbmc_project/Logging/Entry/server.hpp"

#include <phosphor-logging/log.hpp>
#include <sdbusplus/exception.hpp>
#include <tuple>
#include <utility>

namespace phosphor
{

namespace logging
{

using namespace sdbusplus::xyz::openbmc_project::Logging::server;

/**
 * @brief Structure used by callers to indicate they want to use the last value
 *        put in the journal for input parameter.
 */
template <typename T>
struct prev_entry
{
    using type = T;
};

namespace details
{
/**
 * @brief Used to return the generated tuple for the error code meta data
 *
 * The prev_entry (above) and deduce_entry_type structures below are used
 * to verify at compile time the required parameters have been passed to
 * the elog interface and then to forward on the appropriate tuple to the
 * log interface.
 */
template <typename T>
struct deduce_entry_type
{

    using type = T;
    auto get()
    {
        return value._entry;
    }

    T value;
};

/**
 * @brief Used to return an empty tuple for prev_entry parameters
 *
 * This is done so we can still call the log() interface with the variable
 * arg parameters to elog.  The log() interface will simply ignore the empty
 * tuples which is what we want for prev_entry parameters.
 */
template <typename T>
struct deduce_entry_type<prev_entry<T>>
{
    using type = T;
    auto get()
    {
        return std::make_tuple();
    }

    prev_entry<T> value;
};

/**
 * @brief Typedef for above structure usage
 */
template <typename T>
using deduce_entry_type_t = typename deduce_entry_type<T>::type;

/**
 * @brief Used to map an sdbusplus error to a phosphor-logging error type
 *
 * Users log errors via the sdbusplus error name, and the execption that's
 * thrown is the corresponding sdbusplus exception. However, there's a need
 * to map the sdbusplus error name to the phosphor-logging error name, in order
 * to verify the error metadata at compile-time.
 */
template <typename T>
struct map_exception_type
{
    using type = T;
};

/**
 * @brief Typedef for above structure usage
 */
template <typename T>
using map_exception_type_t = typename map_exception_type<T>::type;

/** @fn commit()
 *  @brief Create an error log entry based on journal
 *          entry with a specified exception name
 *  @param[in] name - name of the error exception
 */
void commit(const char* name);

/** @fn commit() - override that accepts error level
 */
void commit(const char* name, Entry::Level level);

} // namespace details

/** @fn commit()
 *  \deprecated use commit<T>()
 *  @brief Create an error log entry based on journal
 *          entry with a specified MSG_ID
 *  @param[in] name - name of the error exception
 */
void commit(std::string&& name);

/** @fn commit()
 *  @brief Create an error log entry based on journal
 *          entry with a specified MSG_ID
 */
template <typename T>
void commit()
{
    // Validate if the exception is derived from sdbusplus::exception.
    static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
                  "T must be a descendant of sdbusplus::exception::exception");
    details::commit(T::errName);
}

/** @fn commit()
 *  @brief Create an error log entry based on journal
 *         entry with a specified MSG_ID. This override accepts error level.
 *  @param[in] level - level of the error
 */
template <typename T>
void commit(Entry::Level level)
{
    // Validate if the exception is derived from sdbusplus::exception.
    static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
                  "T must be a descendant of sdbusplus::exception::exception");
    details::commit(T::errName, level);
}

/** @fn elog()
 *  @brief Create a journal log entry based on predefined
 *          error log information
 *  @tparam T - Error log type
 *  @param[in] i_args - Metadata fields to be added to the journal entry
 */
template <typename T, typename... Args>
[[noreturn]] void elog(Args... i_args) {
    // Validate if the exception is derived from sdbusplus::exception.
    static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
                  "T must be a descendant of sdbusplus::exception::exception");

    // Validate the caller passed in the required parameters<commit_msg>Fix format issue<commit_after>#pragma once
#include "xyz/openbmc_project/Logging/Entry/server.hpp"

#include <phosphor-logging/log.hpp>
#include <sdbusplus/exception.hpp>
#include <tuple>
#include <utility>

namespace phosphor
{

namespace logging
{

using namespace sdbusplus::xyz::openbmc_project::Logging::server;

/**
 * @brief Structure used by callers to indicate they want to use the last value
 *        put in the journal for input parameter.
 */
template <typename T>
struct prev_entry
{
    using type = T;
};

namespace details
{
/**
 * @brief Used to return the generated tuple for the error code meta data
 *
 * The prev_entry (above) and deduce_entry_type structures below are used
 * to verify at compile time the required parameters have been passed to
 * the elog interface and then to forward on the appropriate tuple to the
 * log interface.
 */
template <typename T>
struct deduce_entry_type
{

    using type = T;
    auto get()
    {
        return value._entry;
    }

    T value;
};

/**
 * @brief Used to return an empty tuple for prev_entry parameters
 *
 * This is done so we can still call the log() interface with the variable
 * arg parameters to elog.  The log() interface will simply ignore the empty
 * tuples which is what we want for prev_entry parameters.
 */
template <typename T>
struct deduce_entry_type<prev_entry<T>>
{
    using type = T;
    auto get()
    {
        return std::make_tuple();
    }

    prev_entry<T> value;
};

/**
 * @brief Typedef for above structure usage
 */
template <typename T>
using deduce_entry_type_t = typename deduce_entry_type<T>::type;

/**
 * @brief Used to map an sdbusplus error to a phosphor-logging error type
 *
 * Users log errors via the sdbusplus error name, and the execption that's
 * thrown is the corresponding sdbusplus exception. However, there's a need
 * to map the sdbusplus error name to the phosphor-logging error name, in order
 * to verify the error metadata at compile-time.
 */
template <typename T>
struct map_exception_type
{
    using type = T;
};

/**
 * @brief Typedef for above structure usage
 */
template <typename T>
using map_exception_type_t = typename map_exception_type<T>::type;

/** @fn commit()
 *  @brief Create an error log entry based on journal
 *          entry with a specified exception name
 *  @param[in] name - name of the error exception
 */
void commit(const char* name);

/** @fn commit() - override that accepts error level
 */
void commit(const char* name, Entry::Level level);

} // namespace details

/** @fn commit()
 *  \deprecated use commit<T>()
 *  @brief Create an error log entry based on journal
 *          entry with a specified MSG_ID
 *  @param[in] name - name of the error exception
 */
void commit(std::string&& name);

/** @fn commit()
 *  @brief Create an error log entry based on journal
 *          entry with a specified MSG_ID
 */
template <typename T>
void commit()
{
    // Validate if the exception is derived from sdbusplus::exception.
    static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
                  "T must be a descendant of sdbusplus::exception::exception");
    details::commit(T::errName);
}

/** @fn commit()
 *  @brief Create an error log entry based on journal
 *         entry with a specified MSG_ID. This override accepts error level.
 *  @param[in] level - level of the error
 */
template <typename T>
void commit(Entry::Level level)
{
    // Validate if the exception is derived from sdbusplus::exception.
    static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
                  "T must be a descendant of sdbusplus::exception::exception");
    details::commit(T::errName, level);
}

/** @fn elog()
 *  @brief Create a journal log entry based on predefined
 *          error log information
 *  @tparam T - Error log type
 *  @param[in] i_args - Metadata fields to be added to the journal entry
 */
template <typename T, typename... Args>
[[noreturn]] void elog(Args... i_args)
{
    // Validate if the exception is derived from sdbusplus::exception.
    static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
                  "T must be a descendant of sdbusplus::exception::exception");

    // Validate the caller passed in the required parameters
{'fraction_non_alphanumeric': 0.09921975078607197, 'fraction_numerical': 0.0, 'mean_word_length': 3.5415124272871497, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '3069094', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2457, 'n_words': 975}