ZRColaWS: Make logging systemd journal friendlier
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
450c18198a
commit
c6f844775f
@ -68,7 +68,7 @@ public:
|
|||||||
result->push_back(dto);
|
result->push_back(dto);
|
||||||
return createDtoResponse(Status::CODE_200, result);
|
return createDtoResponse(Status::CODE_200, result);
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
OATPP_LOGE("ZRColaWS", "%s: %s", typeid(ex).name(), ex.what());
|
OATPP_LOGE(__FUNCTION__, "%s: %s", typeid(ex).name(), ex.what());
|
||||||
return ResponseFactory::createResponse(Status::CODE_500, ex.what());
|
return ResponseFactory::createResponse(Status::CODE_500, ex.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ public:
|
|||||||
}
|
}
|
||||||
return createDtoResponse(Status::CODE_200, result);
|
return createDtoResponse(Status::CODE_200, result);
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
OATPP_LOGE("ZRColaWS", "%s: %s", typeid(ex).name(), ex.what());
|
OATPP_LOGE(__FUNCTION__, "%s: %s", typeid(ex).name(), ex.what());
|
||||||
return ResponseFactory::createResponse(Status::CODE_500, ex.what());
|
return ResponseFactory::createResponse(Status::CODE_500, ex.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ public:
|
|||||||
dto->map = map;
|
dto->map = map;
|
||||||
return createDtoResponse(Status::CODE_200, dto);
|
return createDtoResponse(Status::CODE_200, dto);
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
OATPP_LOGE("ZRColaWS", "%s: %s", typeid(ex).name(), ex.what());
|
OATPP_LOGE(__FUNCTION__, "%s: %s", typeid(ex).name(), ex.what());
|
||||||
return ResponseFactory::createResponse(Status::CODE_500, ex.what());
|
return ResponseFactory::createResponse(Status::CODE_500, ex.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ public:
|
|||||||
dto->map = map;
|
dto->map = map;
|
||||||
return createDtoResponse(Status::CODE_200, dto);
|
return createDtoResponse(Status::CODE_200, dto);
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
OATPP_LOGE("ZRColaWS", "%s: %s", typeid(ex).name(), ex.what());
|
OATPP_LOGE(__FUNCTION__, "%s: %s", typeid(ex).name(), ex.what());
|
||||||
return ResponseFactory::createResponse(Status::CODE_500, ex.what());
|
return ResponseFactory::createResponse(Status::CODE_500, ex.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
ZRColaWS/stdlogger.hpp
Normal file
27
ZRColaWS/stdlogger.hpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
Copyright © 2022 Amebis
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <oatpp/core/base/Environment.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
class StdLogger : public oatpp::base::Logger
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::mutex m_lock;
|
||||||
|
|
||||||
|
public:
|
||||||
|
StdLogger() {}
|
||||||
|
|
||||||
|
void log(v_uint32 priority, const std::string& tag, const std::string& message) override
|
||||||
|
{
|
||||||
|
if (!isLogPriorityEnabled(priority))
|
||||||
|
return;
|
||||||
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
(priority < oatpp::base::Logger::PRIORITY_W ? std::cout : std::cerr) << tag << ": " << message << std::endl;
|
||||||
|
}
|
||||||
|
};
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "appcomponent.hpp"
|
#include "appcomponent.hpp"
|
||||||
#include "controller.hpp"
|
#include "controller.hpp"
|
||||||
|
#include "stdlogger.hpp"
|
||||||
#include "zrcolaws.hpp"
|
#include "zrcolaws.hpp"
|
||||||
#include <oatpp-swagger/Controller.hpp>
|
#include <oatpp-swagger/Controller.hpp>
|
||||||
#include <oatpp/core/base/CommandLineArguments.hpp>
|
#include <oatpp/core/base/CommandLineArguments.hpp>
|
||||||
@ -50,61 +51,61 @@ static void load_database()
|
|||||||
if (dat.good()) {
|
if (dat.good()) {
|
||||||
has_translation_data = true;
|
has_translation_data = true;
|
||||||
} else {
|
} else {
|
||||||
OATPP_LOGE("ZRColaWS", "ZRColaWS", "Error reading translation data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
OATPP_LOGE(__FUNCTION__, "Error reading translation data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
t_db.clear();
|
t_db.clear();
|
||||||
}
|
}
|
||||||
} else if (id == transet_rec::id()) {
|
} else if (id == transet_rec::id()) {
|
||||||
dat >> transet_rec(ts_db);
|
dat >> transet_rec(ts_db);
|
||||||
if (!dat.good()) {
|
if (!dat.good()) {
|
||||||
OATPP_LOGE("ZRColaWS", "Error reading translation set data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
OATPP_LOGE(__FUNCTION__, "Error reading translation set data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
ts_db.clear();
|
ts_db.clear();
|
||||||
}
|
}
|
||||||
// } else if (id == transeq_rec::id()) {
|
// } else if (id == transeq_rec::id()) {
|
||||||
// dat >> transeq_rec(tsq_db);
|
// dat >> transeq_rec(tsq_db);
|
||||||
// if (!dat.good()) {
|
// if (!dat.good()) {
|
||||||
// OATPP_LOGE("ZRColaWS", "Error reading translation sequence data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
// OATPP_LOGE(__FUNCTION__, "Error reading translation sequence data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
// tsq_db.clear();
|
// tsq_db.clear();
|
||||||
// }
|
// }
|
||||||
} else if (id == langchar_rec::id()) {
|
} else if (id == langchar_rec::id()) {
|
||||||
dat >> langchar_rec(lc_db);
|
dat >> langchar_rec(lc_db);
|
||||||
if (!dat.good()) {
|
if (!dat.good()) {
|
||||||
OATPP_LOGE("ZRColaWS", "Error reading language character data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
OATPP_LOGE(__FUNCTION__, "Error reading language character data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
lc_db.clear();
|
lc_db.clear();
|
||||||
}
|
}
|
||||||
} else if (id == language_rec::id()) {
|
} else if (id == language_rec::id()) {
|
||||||
dat >> language_rec(lang_db);
|
dat >> language_rec(lang_db);
|
||||||
if (!dat.good()) {
|
if (!dat.good()) {
|
||||||
OATPP_LOGE("ZRColaWS", "Error reading language character data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
OATPP_LOGE(__FUNCTION__, "Error reading language character data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
lang_db.clear();
|
lang_db.clear();
|
||||||
}
|
}
|
||||||
// } else if (id == character_rec::id()) {
|
// } else if (id == character_rec::id()) {
|
||||||
// dat >> character_rec(chr_db);
|
// dat >> character_rec(chr_db);
|
||||||
// if (!dat.good()) {
|
// if (!dat.good()) {
|
||||||
// OATPP_LOGE("ZRColaWS", "Error reading character data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
// OATPP_LOGE(__FUNCTION__, "Error reading character data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
// chr_db.clear();
|
// chr_db.clear();
|
||||||
// }
|
// }
|
||||||
// } else if (id == chrcat_rec::id()) {
|
// } else if (id == chrcat_rec::id()) {
|
||||||
// dat >> chrcat_rec(cc_db);
|
// dat >> chrcat_rec(cc_db);
|
||||||
// if (!dat.good()) {
|
// if (!dat.good()) {
|
||||||
// OATPP_LOGE("ZRColaWS", "Error reading character category data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
// OATPP_LOGE(__FUNCTION__, "Error reading character category data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
// cc_db.clear();
|
// cc_db.clear();
|
||||||
// }
|
// }
|
||||||
// } else if (id == chrtag_rec::id()) {
|
// } else if (id == chrtag_rec::id()) {
|
||||||
// dat >> chrtag_rec(ct_db);
|
// dat >> chrtag_rec(ct_db);
|
||||||
// if (!dat.good()) {
|
// if (!dat.good()) {
|
||||||
// OATPP_LOGE("ZRColaWS", "Error reading character tag data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
// OATPP_LOGE(__FUNCTION__, "Error reading character tag data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
// ct_db.clear();
|
// ct_db.clear();
|
||||||
// }
|
// }
|
||||||
// } else if (id == tagname_rec::id()) {
|
// } else if (id == tagname_rec::id()) {
|
||||||
// dat >> tagname_rec(tn_db);
|
// dat >> tagname_rec(tn_db);
|
||||||
// if (!dat.good()) {
|
// if (!dat.good()) {
|
||||||
// OATPP_LOGE("ZRColaWS", "Error reading tag name data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
// OATPP_LOGE(__FUNCTION__, "Error reading tag name data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
// tn_db.clear();
|
// tn_db.clear();
|
||||||
// }
|
// }
|
||||||
// } else if (id == highlight_rec::id()) {
|
// } else if (id == highlight_rec::id()) {
|
||||||
// dat >> highlight_rec(h_db);
|
// dat >> highlight_rec(h_db);
|
||||||
// if (!dat.good()) {
|
// if (!dat.good()) {
|
||||||
// OATPP_LOGE("ZRColaWS", "Error reading highlight data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
// OATPP_LOGE(__FUNCTION__, "Error reading highlight data from " PREFIX "/share/zrcola/ZRCola.zrcdb.");
|
||||||
// h_db.clear();
|
// h_db.clear();
|
||||||
// }
|
// }
|
||||||
} else
|
} else
|
||||||
@ -118,14 +119,15 @@ static void load_database()
|
|||||||
|
|
||||||
static void sig_handler(int s)
|
static void sig_handler(int s)
|
||||||
{
|
{
|
||||||
OATPP_LOGD("ZRColaWS", "Caught signal %d", s);
|
OATPP_LOGD(__FUNCTION__, "Caught signal %d", s);
|
||||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::Server>, server);
|
OATPP_COMPONENT(std::shared_ptr<oatpp::network::Server>, server);
|
||||||
server->stop();
|
server->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
oatpp::base::Environment::init();
|
auto logger = std::make_shared<StdLogger>();
|
||||||
|
oatpp::base::Environment::init(logger);
|
||||||
try {
|
try {
|
||||||
{
|
{
|
||||||
oatpp::base::CommandLineArguments cmdArgs(argc, argv);
|
oatpp::base::CommandLineArguments cmdArgs(argc, argv);
|
||||||
@ -159,15 +161,15 @@ int main(int argc, const char* argv[])
|
|||||||
auto swaggerController = oatpp::swagger::Controller::createShared(controller->getEndpoints());
|
auto swaggerController = oatpp::swagger::Controller::createShared(controller->getEndpoints());
|
||||||
router->addController(swaggerController);
|
router->addController(swaggerController);
|
||||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
|
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
|
||||||
OATPP_LOGI("ZRColaWS", "Server " PRODUCT_VERSION_STR " starting on %s:%s",
|
OATPP_LOGI(__FUNCTION__, "Server " PRODUCT_VERSION_STR " starting on %s:%s",
|
||||||
connectionProvider->getProperty("host").getData(), connectionProvider->getProperty("port").getData());
|
connectionProvider->getProperty("host").getData(), connectionProvider->getProperty("port").getData());
|
||||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::Server>, server);
|
OATPP_COMPONENT(std::shared_ptr<oatpp::network::Server>, server);
|
||||||
server->run();
|
server->run();
|
||||||
OATPP_LOGI("ZRColaWS", "Server stopped");
|
OATPP_LOGI(__FUNCTION__, "Server stopped");
|
||||||
}
|
}
|
||||||
oatpp::base::Environment::destroy();
|
oatpp::base::Environment::destroy();
|
||||||
} catch (exception &ex) {
|
} catch (exception &ex) {
|
||||||
OATPP_LOGE("ZRColaWS", "%s: %s", typeid(ex).name(), ex.what());
|
OATPP_LOGE(__FUNCTION__, "%s: %s", typeid(ex).name(), ex.what());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user