Esempio n. 1
0
std::ostream& SimpleLogger::formatMessage(std::ostream& os, internal::LogLevel::Level level, const std::string& message, const internal::LogContext& context) {

  if (formatter_ == NULL) {
    os << message;

  } else {
    formatter_(os, level, message, context);
  }

  return (os);
}
Esempio n. 2
0
 void FormattedLogger::log(Severity severity, std::string tag, std::string message) {
   if (severity >= level_) {
     auto t = DateTime::now();
     auto format = formatter_(severity, t, tag, message);
     write_message(severity, wayward::format(format, {
       {"start_color", ""},
       {"end_color", ""},
       {"severity", severity_as_string(severity)},
       {"timestamp", t.strftime("%Y-%m-%d %H:%M:%S")},
       {"tag", std::move(tag)},
       {"message", std::move(message)}
     }));
   }
 }
t_string tslider::get_value_label() const
{
	if(!value_labels_.empty()) {
		assert(value_labels_.size() == get_item_count());
		return value_labels_[get_item_position()];
	} else if(!minimum_value_label_.empty()
			&& get_value() == get_minimum_value()) {
		return minimum_value_label_;
	} else if(!maximum_value_label_.empty()
			&& get_value() == get_maximum_value()) {
		return maximum_value_label_;
	} else {
		return t_string(formatter_(get_value()));
	}
}
Esempio n. 4
0
  void ConsoleStreamLogger::log(Severity severity, std::string tag, std::string message) {
    if (severity >= level()) {
      const char* start_color = "";
      const char* end_color = "";

      if (colorize_) {
        if (severity == Severity::Error) {
          start_color = TerminalRed;
        } else {
          // Locking because we might be modifying tag_colors_.
          std::unique_lock<std::mutex> L(mutex_);

          auto existing_color = tag_colors_.find(tag);
          size_t color_idx;
          if (existing_color == tag_colors_.end()) {
            color_idx = tag_colors_.size() % NumCycleColors;
            tag_colors_[tag] = color_idx;
          } else {
            color_idx = existing_color->second;
          }

          start_color = CycleColors[color_idx];
        }
        end_color = TerminalResetColor;
      }

      auto t = DateTime::now();
      auto format = formatter_(severity, t, tag, message);

      write_message(severity, wayward::format(format, {
        {"start_color", start_color},
        {"end_color", end_color},
        {"severity", severity_as_string(severity)},
        {"timestamp", t.strftime("%Y-%m-%d %H:%M:%S")},
        {"tag", std::move(tag)},
        {"message", std::move(message)}
      }));
    }
  }
 typename formatter_result<Formatter>::type operator()( const T & s ) const {
     BOOST_CHECK( !s.empty() );
     return formatter_(s);
 }