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:
parent
92d8f1f73c
commit
c41e7ce65f
6 changed files with 48 additions and 4 deletions
|
@ -57,6 +57,8 @@ target_link_libraries(${PROJECT_NAME}
|
|||
)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1
|
||||
PRIVATE $<$<CONFIG:Debug>:SPDLOG_DEBUG_ON>
|
||||
PRIVATE $<$<CONFIG:Debug>:SPDLOG_TRACE_ON>
|
||||
)
|
||||
target_compile_options(${PROJECT_NAME}
|
||||
PRIVATE -fdiagnostics-color=always
|
||||
|
|
|
@ -85,7 +85,7 @@ int main() {
|
|||
spdlog::set_level(spdlog::level::trace); //set to maximum possible here
|
||||
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());
|
||||
conf >> std::noskipws;
|
||||
|
@ -102,6 +102,7 @@ int main() {
|
|||
|
||||
tawashi::cgi::Env cgi_env;
|
||||
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("", &make_response<IndexResponse>);
|
||||
resp_factory.register_maker("paste.cgi", &make_response<SubmitPasteResponse>);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <functional>
|
||||
#include <boost/optional.hpp>
|
||||
#include <cstdint>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace tawashi {
|
||||
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) {
|
||||
std::ostringstream oss;
|
||||
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);
|
||||
|
||||
if (not if_mstch) {
|
||||
|
@ -118,6 +119,14 @@ namespace tawashi {
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -129,6 +138,11 @@ namespace tawashi {
|
|||
}
|
||||
|
||||
void Response::send() {
|
||||
auto statuslog = spdlog::get("statuslog");
|
||||
assert(statuslog);
|
||||
|
||||
statuslog->info("Sending response");
|
||||
SPDLOG_TRACE(statuslog, "Preparing mustache dictionary");
|
||||
mstch::map mustache_context {
|
||||
{"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
|
||||
{"base_uri", m_settings->as<std::string>("base_uri")},
|
||||
|
@ -136,6 +150,7 @@ namespace tawashi {
|
|||
};
|
||||
|
||||
if (m_redis) {
|
||||
SPDLOG_TRACE(statuslog, "Finalizing redis connection");
|
||||
m_redis->wait_for_connect();
|
||||
auto batch = m_redis->make_batch();
|
||||
batch.select(m_settings->as<uint32_t>("redis_db"));
|
||||
|
@ -143,19 +158,24 @@ namespace tawashi {
|
|||
batch.throw_if_failed();
|
||||
}
|
||||
|
||||
SPDLOG_TRACE(statuslog, "Raising event on_process");
|
||||
this->on_process();
|
||||
SPDLOG_TRACE(statuslog, "Raising event on_mustache_prepare");
|
||||
this->on_mustache_prepare(mustache_context);
|
||||
|
||||
m_header_sent = true;
|
||||
switch (m_resp_type) {
|
||||
case ContentType:
|
||||
SPDLOG_TRACE(statuslog, "Response is a Content-type (data)");
|
||||
std::cout << "Content-type: " << m_resp_value << "\n\n";
|
||||
break;
|
||||
case Location:
|
||||
SPDLOG_TRACE(statuslog, "Response is a Location (redirect)");
|
||||
std::cout << "Location: " << m_resp_value << "\n\n";
|
||||
break;
|
||||
}
|
||||
|
||||
SPDLOG_TRACE(statuslog, "Rendering in mustache");
|
||||
std::cout << mstch::render(
|
||||
on_mustache_retrieve(),
|
||||
mustache_context,
|
||||
|
@ -167,6 +187,7 @@ namespace tawashi {
|
|||
false
|
||||
)
|
||||
);
|
||||
SPDLOG_TRACE(statuslog, "Flushing output");
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,13 @@ namespace tawashi {
|
|||
m_local_data(std::make_unique<LocalData>())
|
||||
{
|
||||
m_local_data->settings = parSettings;
|
||||
|
||||
}
|
||||
|
||||
ResponseFactory::~ResponseFactory() noexcept = default;
|
||||
|
||||
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()));
|
||||
if (m_local_data->makers.end() != maker_it) {
|
||||
return maker_it->second(m_local_data->settings);
|
||||
|
|
|
@ -21,11 +21,26 @@
|
|||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
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) :
|
||||
m_ini(parIni),
|
||||
m_values(&parIni->parsed().at("tawashi"))
|
||||
m_values(get_tawashi_node(*parIni))
|
||||
{
|
||||
assert(m_values);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include <boost/utility/string_ref.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#if defined(SPDLOG_DEBUG_ON)
|
||||
# include <spdlog/spdlog.h>
|
||||
#endif
|
||||
|
||||
namespace tawashi {
|
||||
class SettingsBag : public Kakoune::SafeCountable {
|
||||
|
@ -48,6 +51,7 @@ namespace tawashi {
|
|||
}
|
||||
|
||||
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];
|
||||
}
|
||||
} //namespace tawashi
|
||||
|
|
Loading…
Add table
Reference in a new issue