From 5f0ea562416b9e20bd7c3024239f040158276673 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 8 Jun 2017 21:33:18 +0100 Subject: [PATCH] Log raw pastie from POST and pastie before going to redis. This is to hopefully track down the pastie corruption bug that I'm only encountering on the outgoing server. --- src/tawashi/cgi_post.cpp | 9 +++++++++ src/tawashi/storage.cpp | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/tawashi/cgi_post.cpp b/src/tawashi/cgi_post.cpp index 3fea03a..35c90ba 100644 --- a/src/tawashi/cgi_post.cpp +++ b/src/tawashi/cgi_post.cpp @@ -20,6 +20,10 @@ #include "split_get_vars.hpp" #include "escapist.hpp" #include "sanitized_utf8.hpp" +#include "spdlog.hpp" +#if defined(SPDLOG_DEBUG_ON) +# include "truncated_string.hpp" +#endif #include #include #include @@ -80,6 +84,11 @@ namespace tawashi { original_data = read_n(parSrc, input_len); Escapist houdini; for (auto& itm : split_env_vars(original_data)) { +#if defined(SPDLOG_DEBUG_ON) + if (itm.first == "pastie") { + spdlog::get("statuslog")->debug("Raw pastie from POST, size={}: \"{}\"", itm.second.size(), truncated_string(itm.second, 30)); + } +#endif std::string key(houdini.unescape_url(itm.first)); std::string val(houdini.unescape_url(itm.second)); map[std::move(key)] = std::move(val); diff --git a/src/tawashi/storage.cpp b/src/tawashi/storage.cpp index ae5ba1a..9a4d0d1 100644 --- a/src/tawashi/storage.cpp +++ b/src/tawashi/storage.cpp @@ -22,10 +22,12 @@ #include "tawashi_config.h" #include "duckhandy/stringize.h" #include "spdlog.hpp" +#include "truncated_string.hpp" #include #include #include #include +#include namespace tawashi { namespace { @@ -104,6 +106,15 @@ namespace tawashi { return make_submission_result(ErrorReasons::UserFlooding); } + auto statuslog = spdlog::get("statuslog"); + if (statuslog->should_log(spdlog::level::info)) { + statuslog->info( + "Submitting pastie of size {} to redis -> \"{}\"", + parText.size(), + truncated_string(parText, 30) + ); + } + const auto next_id = redis.incr("paste_counter"); std::string token = num_to_token(next_id); assert(not token.empty());