1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-02-09 09:23:56 +00:00

Add more logging

This commit is contained in:
King_DuckZ 2017-05-04 10:00:49 +01:00
parent 92d8f1f73c
commit c41e7ce65f
6 changed files with 48 additions and 4 deletions

View file

@ -57,6 +57,8 @@ target_link_libraries(${PROJECT_NAME}
) )
target_compile_definitions(${PROJECT_NAME} target_compile_definitions(${PROJECT_NAME}
PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1 PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1
PRIVATE $<$<CONFIG:Debug>:SPDLOG_DEBUG_ON>
PRIVATE $<$<CONFIG:Debug>:SPDLOG_TRACE_ON>
) )
target_compile_options(${PROJECT_NAME} target_compile_options(${PROJECT_NAME}
PRIVATE -fdiagnostics-color=always PRIVATE -fdiagnostics-color=always

View file

@ -85,7 +85,7 @@ int main() {
spdlog::set_level(spdlog::level::trace); //set to maximum possible here spdlog::set_level(spdlog::level::trace); //set to maximum possible here
auto statuslog = spdlog::stderr_logger_st("statuslog"); auto statuslog = spdlog::stderr_logger_st("statuslog");
statuslog->debug("Loading config: \"{}\"\n", config_file_path()); statuslog->info("Loading config: \"{}\"", config_file_path());
std::ifstream conf(config_file_path()); std::ifstream conf(config_file_path());
conf >> std::noskipws; conf >> std::noskipws;
@ -102,6 +102,7 @@ int main() {
tawashi::cgi::Env cgi_env; tawashi::cgi::Env cgi_env;
tawashi::ResponseFactory resp_factory(settings); tawashi::ResponseFactory resp_factory(settings);
SPDLOG_TRACE(statuslog, "Registering makers in the response factory");
resp_factory.register_maker("index.cgi", &make_response<IndexResponse>); resp_factory.register_maker("index.cgi", &make_response<IndexResponse>);
resp_factory.register_maker("", &make_response<IndexResponse>); resp_factory.register_maker("", &make_response<IndexResponse>);
resp_factory.register_maker("paste.cgi", &make_response<SubmitPasteResponse>); resp_factory.register_maker("paste.cgi", &make_response<SubmitPasteResponse>);

View file

@ -29,6 +29,7 @@
#include <functional> #include <functional>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <cstdint> #include <cstdint>
#include <spdlog/spdlog.h>
namespace tawashi { namespace tawashi {
namespace { namespace {
@ -74,7 +75,7 @@ namespace tawashi {
boost::optional<std::string> load_whole_file (const std::string& parWebsiteRoot, const char* parSuffix, const std::string& parName, bool parThrow) { boost::optional<std::string> load_whole_file (const std::string& parWebsiteRoot, const char* parSuffix, const std::string& parName, bool parThrow) {
std::ostringstream oss; std::ostringstream oss;
oss << parWebsiteRoot << parName << parSuffix; oss << parWebsiteRoot << parName << parSuffix;
std::cerr << "Trying to load \"" << oss.str() << "\"\n"; spdlog::get("statuslog")->debug("Trying to load \"{}\"", oss.str());
std::ifstream if_mstch(oss.str(), std::ios::binary | std::ios::in); std::ifstream if_mstch(oss.str(), std::ios::binary | std::ios::in);
if (not if_mstch) { if (not if_mstch) {
@ -118,6 +119,14 @@ namespace tawashi {
} }
mstch::config::escape = &disable_mstch_escaping; mstch::config::escape = &disable_mstch_escaping;
auto statuslog = spdlog::get("statuslog");
assert(statuslog);
statuslog->info("Preparing Response for {} request to {}; size: {}",
cgi_env().request_method(),
cgi_env().query_string(),
cgi_env().content_length()
);
} }
Response::~Response() noexcept = default; Response::~Response() noexcept = default;
@ -129,6 +138,11 @@ namespace tawashi {
} }
void Response::send() { void Response::send() {
auto statuslog = spdlog::get("statuslog");
assert(statuslog);
statuslog->info("Sending response");
SPDLOG_TRACE(statuslog, "Preparing mustache dictionary");
mstch::map mustache_context { mstch::map mustache_context {
{"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}}, {"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
{"base_uri", m_settings->as<std::string>("base_uri")}, {"base_uri", m_settings->as<std::string>("base_uri")},
@ -136,6 +150,7 @@ namespace tawashi {
}; };
if (m_redis) { if (m_redis) {
SPDLOG_TRACE(statuslog, "Finalizing redis connection");
m_redis->wait_for_connect(); m_redis->wait_for_connect();
auto batch = m_redis->make_batch(); auto batch = m_redis->make_batch();
batch.select(m_settings->as<uint32_t>("redis_db")); batch.select(m_settings->as<uint32_t>("redis_db"));
@ -143,19 +158,24 @@ namespace tawashi {
batch.throw_if_failed(); batch.throw_if_failed();
} }
SPDLOG_TRACE(statuslog, "Raising event on_process");
this->on_process(); this->on_process();
SPDLOG_TRACE(statuslog, "Raising event on_mustache_prepare");
this->on_mustache_prepare(mustache_context); this->on_mustache_prepare(mustache_context);
m_header_sent = true; m_header_sent = true;
switch (m_resp_type) { switch (m_resp_type) {
case ContentType: case ContentType:
SPDLOG_TRACE(statuslog, "Response is a Content-type (data)");
std::cout << "Content-type: " << m_resp_value << "\n\n"; std::cout << "Content-type: " << m_resp_value << "\n\n";
break; break;
case Location: case Location:
SPDLOG_TRACE(statuslog, "Response is a Location (redirect)");
std::cout << "Location: " << m_resp_value << "\n\n"; std::cout << "Location: " << m_resp_value << "\n\n";
break; break;
} }
SPDLOG_TRACE(statuslog, "Rendering in mustache");
std::cout << mstch::render( std::cout << mstch::render(
on_mustache_retrieve(), on_mustache_retrieve(),
mustache_context, mustache_context,
@ -167,6 +187,7 @@ namespace tawashi {
false false
) )
); );
SPDLOG_TRACE(statuslog, "Flushing output");
std::cout.flush(); std::cout.flush();
} }

View file

@ -34,12 +34,13 @@ namespace tawashi {
m_local_data(std::make_unique<LocalData>()) m_local_data(std::make_unique<LocalData>())
{ {
m_local_data->settings = parSettings; m_local_data->settings = parSettings;
} }
ResponseFactory::~ResponseFactory() noexcept = default; ResponseFactory::~ResponseFactory() noexcept = default;
std::unique_ptr<Response> ResponseFactory::make_response (const boost::string_ref& parName) { std::unique_ptr<Response> ResponseFactory::make_response (const boost::string_ref& parName) {
//spdlog::get("statuslog")->info("making response object for \"{}\"", parName);
auto maker_it = m_local_data->makers.find(std::string(parName.data(), parName.size())); auto maker_it = m_local_data->makers.find(std::string(parName.data(), parName.size()));
if (m_local_data->makers.end() != maker_it) { if (m_local_data->makers.end() != maker_it) {
return maker_it->second(m_local_data->settings); return maker_it->second(m_local_data->settings);

View file

@ -21,11 +21,26 @@
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
#include <sstream> #include <sstream>
#include <spdlog/spdlog.h>
namespace tawashi { namespace tawashi {
namespace {
const IniFile::KeyValueMapType* get_tawashi_node (const IniFile& parIni) {
auto it_found = parIni.parsed().find("tawashi");
if (parIni.parsed().end() != it_found) {
return &it_found->second;
}
else {
spdlog::get("statuslog")->warn("Couldn't find section [tawashi] in the settings file");
static const IniFile::KeyValueMapType empty_key_values;
return &empty_key_values;
}
}
} //unnamed namespace
SettingsBag::SettingsBag (const Kakoune::SafePtr<IniFile>& parIni) : SettingsBag::SettingsBag (const Kakoune::SafePtr<IniFile>& parIni) :
m_ini(parIni), m_ini(parIni),
m_values(&parIni->parsed().at("tawashi")) m_values(get_tawashi_node(*parIni))
{ {
assert(m_values); assert(m_values);
} }

View file

@ -23,6 +23,9 @@
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_ref.hpp>
#include <functional> #include <functional>
#include <string> #include <string>
#if defined(SPDLOG_DEBUG_ON)
# include <spdlog/spdlog.h>
#endif
namespace tawashi { namespace tawashi {
class SettingsBag : public Kakoune::SafeCountable { class SettingsBag : public Kakoune::SafeCountable {
@ -48,6 +51,7 @@ namespace tawashi {
} }
inline const boost::string_ref& SettingsBag::at (boost::string_ref parIndex) const { inline const boost::string_ref& SettingsBag::at (boost::string_ref parIndex) const {
SPDLOG_DEBUG(spdlog::get("statuslog"), "Retrieving setting \"{}\"", std::string(parIndex.data(), parIndex.size()));
return (*this)[parIndex]; return (*this)[parIndex];
} }
} //namespace tawashi } //namespace tawashi