<commit_before>#include <cassert>
#include <syslog.h>
#include "But/Log/Backend/toString.hpp"
#include "But/Log/Backend/trimNonPrintable.hpp"
#include "Syslog.hpp"

namespace But
{
namespace Log
{
namespace Destination
{

namespace
{
auto toSyslogPriority(const Field::Priority p)
{
  switch(p)
  {
    case Field::Priority::debug:   return LOG_DEBUG;
    case Field::Priority::info:    return LOG_INFO;
    case Field::Priority::warning: return LOG_WARNING;
    case Field::Priority::error:   return LOG_ERR;
  }
  assert(!"unknown priority");
  throw std::logic_error{"unknown priority"};
}

auto stringToPriority(std::string const& str)
{
  if( str == toString(Field::Priority::debug) )   return Field::Priority::debug;
  if( str == toString(Field::Priority::info) )    return Field::Priority::info;
  if( str == toString(Field::Priority::warning) ) return Field::Priority::warning;
  if( str == toString(Field::Priority::error) )   return Field::Priority::error;
  assert(!"unknown priority string");
  throw std::logic_error{"unknown priority string: " + str};
}
}

void Syslog::logImpl(Backend::Entry e)
{
  auto pri = toString(Field::Priority::info);
  std::stringstream ss;
  for(auto& f: e)
  {
    ss << Backend::trimNonPrintable( f.value() );
    if( f.type() == typeString(Field::Priority::info) )
      pri = f.value();
  }
  const auto p = stringToPriority(pri);
  const auto slp = toSyslogPriority(p);
  syslog( slp, "%s", ss.str().c_str() );
}

}
}
}<commit_msg>move-operator when logging to syslog<commit_after>#include <cassert>
#include <syslog.h>
#include "But/Log/Backend/toString.hpp"
#include "But/Log/Backend/trimNonPrintable.hpp"
#include "Syslog.hpp"

namespace But
{
namespace Log
{
namespace Destination
{

namespace
{
auto toSyslogPriority(const Field::Priority p)
{
  switch(p)
  {
    case Field::Priority::debug:   return LOG_DEBUG;
    case Field::Priority::info:    return LOG_INFO;
    case Field::Priority::warning: return LOG_WARNING;
    case Field::Priority::error:   return LOG_ERR;
  }
  assert(!"unknown priority");
  throw std::logic_error{"unknown priority"};
}

auto stringToPriority(std::string const& str)
{
  if( str == toString(Field::Priority::debug) )   return Field::Priority::debug;
  if( str == toString(Field::Priority::info) )    return Field::Priority::info;
  if( str == toString(Field::Priority::warning) ) return Field::Priority::warning;
  if( str == toString(Field::Priority::error) )   return Field::Priority::error;
  assert(!"unknown priority string");
  throw std::logic_error{"unknown priority string: " + str};
}
}

void Syslog::logImpl(Backend::Entry e)
{
  auto pri = toString(Field::Priority::info);
  std::stringstream ss;
  for(auto& f: e)
  {
    ss << Backend::trimNonPrintable( std::move(f).value() );
    if( f.type() == typeString(Field::Priority::info) )
      pri = f.value();
  }
  const auto p = stringToPriority(pri);
  const auto slp = toSyslogPriority(p);
  syslog( slp, "%s", ss.str().c_str() );
}

}
}
}
{'fraction_non_alphanumeric': 0.16220735785953178, 'fraction_numerical': 0.0, 'mean_word_length': 5.054655870445344, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '5197330', 'n_tokens_mistral': 986, 'n_tokens_neox': 990, 'n_words': 216}