1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-11-23 00:33:44 +00:00

Make logging level configurable in tawashi.ini.

This commit is contained in:
King_DuckZ 2017-05-04 09:59:49 +01:00
parent c892ed2df8
commit 92d8f1f73c
3 changed files with 42 additions and 1 deletions

View file

@ -4,3 +4,4 @@ redis_port = 6379
redis_mode = inet
base_uri = http://127.0.0.1:8080
website_root = /home/michele/dev/code/cpp/tawashi/html
logging_level = trace

33
src/logging_levels.hpp Normal file
View file

@ -0,0 +1,33 @@
/* Copyright 2017, Michele Santullo
* This file is part of "tawashi".
*
* "tawashi" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "tawashi" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "enum.h"
#include <spdlog/spdlog.h>
namespace tawashi {
BETTER_ENUM(LoggingLevels, int,
trace = spdlog::level::trace,
debug = spdlog::level::debug,
info = spdlog::level::info,
warn = spdlog::level::warn,
err = spdlog::level::err,
critical = spdlog::level::critical,
off = spdlog::level::off
);
} //namespace tawashi

View file

@ -26,6 +26,7 @@
#include "pathname/pathname.hpp"
#include "duckhandy/compatibility.h"
#include "settings_bag.hpp"
#include "logging_levels.hpp"
#include <spdlog/spdlog.h>
#include <string>
#include <fstream>
@ -68,6 +69,7 @@ namespace {
parSettings.add_default("min_pastie_size", "10");
parSettings.add_default("max_pastie_size", "10000");
parSettings.add_default("truncate_long_pasties", "false");
parSettings.add_default("logging_level", "err");
}
} //unnamed namespace
@ -80,7 +82,7 @@ int main() {
//Prepare the logger
spdlog::set_pattern("[%Y-%m-%d %T %z] - %v");
spdlog::set_level(spdlog::level::debug);
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());
@ -93,6 +95,11 @@ int main() {
auto settings = SafeStackObject<tawashi::SettingsBag>(ini);
fill_defaults(*settings);
{
auto logging_level = tawashi::LoggingLevels::_from_string_nocase(settings->as<std::string>("logging_level").c_str());
spdlog::set_level(static_cast<decltype(spdlog::level::trace)>(logging_level._to_integral()));
}
tawashi::cgi::Env cgi_env;
tawashi::ResponseFactory resp_factory(settings);
resp_factory.register_maker("index.cgi", &make_response<IndexResponse>);