mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
update error logging and reading config.. both fro default system pathes
This commit is contained in:
parent
1eb108b236
commit
bca54d1885
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -10,3 +10,6 @@
|
||||
[submodule "dependencies/iroha-ed25519"]
|
||||
path = dependencies/iroha-ed25519
|
||||
url = ssh://git@***REMOVED***/~/Forks/iroha-ed25519.git
|
||||
[submodule "dependencies/spirit-po"]
|
||||
path = dependencies/spirit-po
|
||||
url = https://github.com/cbeck88/spirit-po.git
|
||||
|
||||
@ -10,6 +10,7 @@ include_directories(
|
||||
"dependencies/iroha-ed25519/include"
|
||||
"dependencies/mariadb-connector-c/include"
|
||||
"dependencies/mariadb-connector-c/build/include"
|
||||
"dependencies/spirit-po/include"
|
||||
#"dependencies/mariadb-connector-c/build/include"
|
||||
#"dependencies/mariadb-connector-c/include"
|
||||
#"import/mariadb/include"
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
Poco/1.9.4@pocoproject/stable
|
||||
libsodium/1.0.18@bincrafters/stable
|
||||
protobuf/3.9.1@bincrafters/stable
|
||||
|
||||
boost/1.71.0@conan/stable
|
||||
|
||||
[generators]
|
||||
cmake
|
||||
|
||||
1
dependencies/spirit-po
vendored
Submodule
1
dependencies/spirit-po
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 336789e62363357d87894983e6cbdd6da6c838ea
|
||||
@ -15,6 +15,7 @@
|
||||
#include "Poco/Net/SSLManager.h"
|
||||
#include "Poco/Environment.h"
|
||||
#include "Poco/Logger.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/AsyncChannel.h"
|
||||
#include "Poco/SimpleFileChannel.h"
|
||||
#include "Poco/ConsoleChannel.h"
|
||||
@ -72,6 +73,22 @@ void Gradido_LoginServer::displayHelp()
|
||||
helpFormatter.format(std::cout);
|
||||
}
|
||||
|
||||
void Gradido_LoginServer::createConsoleFileAsyncLogger(std::string name, std::string filePath)
|
||||
{
|
||||
Poco::AutoPtr<Poco::ConsoleChannel> logConsoleChannel(new Poco::ConsoleChannel);
|
||||
Poco::AutoPtr<Poco::SimpleFileChannel> logFileChannel(new Poco::SimpleFileChannel(filePath));
|
||||
logFileChannel->setProperty("rotation", "500 K");
|
||||
Poco::AutoPtr<Poco::SplitterChannel> logSplitter(new Poco::SplitterChannel);
|
||||
logSplitter->addChannel(logConsoleChannel);
|
||||
logSplitter->addChannel(logFileChannel);
|
||||
|
||||
Poco::AutoPtr<Poco::AsyncChannel> logAsyncChannel(new Poco::AsyncChannel(logSplitter));
|
||||
|
||||
Poco::Logger& log = Poco::Logger::get(name);
|
||||
log.setChannel(logAsyncChannel);
|
||||
log.setLevel("information");
|
||||
}
|
||||
|
||||
int Gradido_LoginServer::main(const std::vector<std::string>& args)
|
||||
{
|
||||
Profiler usedTime;
|
||||
@ -81,16 +98,53 @@ int Gradido_LoginServer::main(const std::vector<std::string>& args)
|
||||
}
|
||||
else
|
||||
{
|
||||
// ********** logging ************************************
|
||||
std::string log_Path = "/var/log/grd_login/";
|
||||
#ifdef _WIN32 || _WIN64
|
||||
log_Path = "./";
|
||||
#endif
|
||||
|
||||
// init speed logger
|
||||
Poco::AutoPtr<Poco::SimpleFileChannel> speedLogFileChannel(new Poco::SimpleFileChannel(log_Path + "speedLog.txt"));
|
||||
/*
|
||||
The optional log file rotation mode:
|
||||
never: no rotation (default)
|
||||
<n>: rotate if file size exceeds <n> bytes
|
||||
<n> K: rotate if file size exceeds <n> Kilobytes
|
||||
<n> M: rotate if file size exceeds <n> Megabytes
|
||||
*/
|
||||
speedLogFileChannel->setProperty("rotation", "500 K");
|
||||
Poco::AutoPtr<Poco::AsyncChannel> speedLogAsyncChannel(new Poco::AsyncChannel(speedLogFileChannel));
|
||||
|
||||
Poco::Logger& speedLogger = Poco::Logger::get("SpeedLog");
|
||||
speedLogger.setChannel(speedLogAsyncChannel);
|
||||
speedLogger.setLevel("information");
|
||||
|
||||
// logging for request handling
|
||||
createConsoleFileAsyncLogger("requestLog", log_Path + "requestLog.txt");
|
||||
|
||||
// error logging
|
||||
createConsoleFileAsyncLogger("errorLog", log_Path + "errorLog.txt");
|
||||
Poco::Logger& errorLog = Poco::Logger::get("errorLog");
|
||||
|
||||
// *************** load from config ********************************************
|
||||
|
||||
std::string cfg_Path = Poco::Path::config() + "grd_login/";
|
||||
loadConfiguration(cfg_Path + "grd_login.properties");
|
||||
|
||||
unsigned short port = (unsigned short)config().getInt("HTTPServer.port", 9980);
|
||||
unsigned short json_port = (unsigned short)config().getInt("JSONServer.port", 1201);
|
||||
|
||||
|
||||
// load word lists
|
||||
if (!ServerConfig::loadMnemonicWordLists()) {
|
||||
printf("[Gradido_LoginServer::%s] error loading mnemonic Word List\n", __FUNCTION__);
|
||||
//printf("[Gradido_LoginServer::%s] error loading mnemonic Word List\n", __FUNCTION__);
|
||||
errorLog.error("[Gradido_LoginServer::main] error loading mnemonic Word List");
|
||||
return Application::EXIT_CONFIG;
|
||||
}
|
||||
if (!ServerConfig::initServerCrypto(config())) {
|
||||
printf("[Gradido_LoginServer::%s] error init server crypto\n", __FUNCTION__);
|
||||
//printf("[Gradido_LoginServer::%s] error init server crypto\n", __FUNCTION__);
|
||||
errorLog.error("[Gradido_LoginServer::main] error init server crypto");
|
||||
return Application::EXIT_CONFIG;
|
||||
}
|
||||
|
||||
@ -103,22 +157,6 @@ int Gradido_LoginServer::main(const std::vector<std::string>& args)
|
||||
// start cpu scheduler
|
||||
uint8_t worker_count = Poco::Environment::processorCount() * 2;
|
||||
|
||||
// init speed logger
|
||||
Poco::AutoPtr<Poco::SimpleFileChannel> speedLogFileChannel(new Poco::SimpleFileChannel("speedLog.txt"));
|
||||
/*
|
||||
The optional log file rotation mode:
|
||||
never: no rotation (default)
|
||||
<n>: rotate if file size exceeds <n> bytes
|
||||
<n> K: rotate if file size exceeds <n> Kilobytes
|
||||
<n> M: rotate if file size exceeds <n> Megabytes
|
||||
*/
|
||||
speedLogFileChannel->setProperty("rotation", "500 K");
|
||||
Poco::AutoPtr<Poco::AsyncChannel> speedLogAsyncChannel(new Poco::AsyncChannel(speedLogFileChannel));
|
||||
|
||||
Poco::Logger& speedLogger = Poco::Logger::get("SpeedLog");
|
||||
speedLogger.setChannel(speedLogAsyncChannel);
|
||||
speedLogger.setLevel("information");
|
||||
|
||||
ServerConfig::g_CPUScheduler = new UniLib::controller::CPUSheduler(worker_count, "Default Worker");
|
||||
ServerConfig::g_CryptoCPUScheduler = new UniLib::controller::CPUSheduler(2, "Crypto Worker");
|
||||
|
||||
@ -139,23 +177,12 @@ int Gradido_LoginServer::main(const std::vector<std::string>& args)
|
||||
|
||||
Poco::Net::initializeSSL();
|
||||
if(!ServerConfig::initSSLClientContext()) {
|
||||
printf("[Gradido_LoginServer::%s] error init server SSL Client\n", __FUNCTION__);
|
||||
//printf("[Gradido_LoginServer::%s] error init server SSL Client\n", __FUNCTION__);
|
||||
errorLog.error("[Gradido_LoginServer::main] error init server SSL Client\n");
|
||||
return Application::EXIT_CONFIG;
|
||||
}
|
||||
|
||||
// logging for request handling
|
||||
Poco::AutoPtr<Poco::ConsoleChannel> requestLogConsoleChannel(new Poco::ConsoleChannel);
|
||||
Poco::AutoPtr<Poco::SimpleFileChannel> requestLogFileChannel(new Poco::SimpleFileChannel("requestLog.txt"));
|
||||
requestLogFileChannel->setProperty("rotation", "500 K");
|
||||
Poco::AutoPtr<Poco::SplitterChannel> requestLogSplitter(new Poco::SplitterChannel);
|
||||
requestLogSplitter->addChannel(requestLogConsoleChannel);
|
||||
requestLogSplitter->addChannel(requestLogFileChannel);
|
||||
|
||||
Poco::AutoPtr<Poco::AsyncChannel> requestLogAsyncChannel(new Poco::AsyncChannel(requestLogSplitter));
|
||||
|
||||
Poco::Logger& requestLog = Poco::Logger::get("requestLog");
|
||||
requestLog.setChannel(requestLogAsyncChannel);
|
||||
requestLog.setLevel("information");
|
||||
|
||||
// HTTP Interface Server
|
||||
// set-up a server socket
|
||||
|
||||
@ -32,6 +32,8 @@ protected:
|
||||
|
||||
int main(const std::vector<std::string>& args);
|
||||
|
||||
void createConsoleFileAsyncLogger(std::string name, std::string filePath);
|
||||
|
||||
private:
|
||||
bool _helpRequested;
|
||||
};
|
||||
|
||||
@ -42,6 +42,8 @@ namespace ServerConfig {
|
||||
std::string g_php_serverHost;
|
||||
Poco::Mutex g_TimeMutex;
|
||||
|
||||
|
||||
|
||||
bool loadMnemonicWordLists()
|
||||
{
|
||||
for (int i = 0; i < MNEMONIC_MAX; i++) {
|
||||
|
||||
@ -41,7 +41,6 @@ namespace ServerConfig {
|
||||
extern std::string g_php_serverHost;
|
||||
extern Poco::Mutex g_TimeMutex;
|
||||
|
||||
|
||||
bool loadMnemonicWordLists();
|
||||
bool initServerCrypto(const Poco::Util::LayeredConfiguration& cfg);
|
||||
bool initEMailAccount(const Poco::Util::LayeredConfiguration& cfg);
|
||||
|
||||
@ -14,6 +14,7 @@ ErrorManager* ErrorManager::getInstance()
|
||||
}
|
||||
|
||||
ErrorManager::ErrorManager()
|
||||
: mLogging(Poco::Logger::get("errorLog"))
|
||||
{
|
||||
|
||||
}
|
||||
@ -36,7 +37,10 @@ void ErrorManager::addError(Error* error)
|
||||
auto it = mErrorsMap.find(id);
|
||||
std::list<Error*>* list = nullptr;
|
||||
|
||||
printf("[ErrorManager::addError] error with function: %s, %s\n", error->getFunctionName(), error->getMessage());
|
||||
//printf("[ErrorManager::addError] error with function: %s, %s\n", error->getFunctionName(), error->getMessage());
|
||||
mLogging.error("[ErrorManager::addError] error with function: %s, %s",
|
||||
std::string(error->getFunctionName()), std::string(error->getMessage())
|
||||
);
|
||||
|
||||
if (it == mErrorsMap.end()) {
|
||||
list = new std::list<Error *>;
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "../tasks/CPUTask.h"
|
||||
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Logger.h"
|
||||
#include "Poco/Net/MailMessage.h"
|
||||
|
||||
|
||||
@ -45,6 +46,8 @@ protected:
|
||||
std::map<DHASH, std::list<Error*>*> mErrorsMap;
|
||||
// how many errors should be stored
|
||||
|
||||
// poco logging
|
||||
Poco::Logger& mLogging;
|
||||
};
|
||||
|
||||
|
||||
|
||||
92
src/cpp/SingletonManager/LanguageManager.cpp
Normal file
92
src/cpp/SingletonManager/LanguageManager.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
#include "LanguageManager.h"
|
||||
|
||||
LanguageCatalog::LanguageCatalog(Languages lang)
|
||||
: mReferenceCount(1), mCatalog(nullptr), mThisLanguage(lang)
|
||||
{
|
||||
// TODO: Catalog init code
|
||||
}
|
||||
|
||||
LanguageCatalog::~LanguageCatalog()
|
||||
{
|
||||
if (mCatalog) {
|
||||
delete mCatalog;
|
||||
mCatalog = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void LanguageCatalog::release()
|
||||
{
|
||||
lock();
|
||||
mReferenceCount--;
|
||||
bool canReturnPointer = false;
|
||||
if (mReferenceCount <= 0) {
|
||||
canReturnPointer = true;
|
||||
}
|
||||
unlock();
|
||||
|
||||
if (canReturnPointer) {
|
||||
//return pointer
|
||||
LanguageManager::getInstance()->returnCatalog(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ******************************************************
|
||||
|
||||
LanguageManager* LanguageManager::getInstance()
|
||||
{
|
||||
static LanguageManager only;
|
||||
return &only;
|
||||
}
|
||||
|
||||
LanguageManager::LanguageManager()
|
||||
: mLogging(Poco::Logger::get("errorLog"))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LanguageManager::~LanguageManager()
|
||||
{
|
||||
lock();
|
||||
for (int lang = 0; lang < LANG_COUNT; lang++) {
|
||||
for (auto it = mFreeCatalogs[lang].begin(); it != mFreeCatalogs[lang].end(); it++) {
|
||||
delete *it;
|
||||
}
|
||||
mFreeCatalogs[lang].clear();
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
void LanguageManager::returnCatalog(LanguageCatalog* catalog)
|
||||
{
|
||||
if (!catalog) return;
|
||||
if (catalog->getLanguage() >= LANG_COUNT) {
|
||||
//printf("[LanguageManager::returnCatalog] invalid language: %d\n", catalog->getLanguage());
|
||||
mLogging.error("[LanguageManager::returnCatalog] invalid language: %d", catalog->getLanguage());
|
||||
delete catalog;
|
||||
return;
|
||||
}
|
||||
lock();
|
||||
mFreeCatalogs[catalog->getLanguage()].push_back(catalog);
|
||||
unlock();
|
||||
}
|
||||
|
||||
Poco::AutoPtr<LanguageCatalog> LanguageManager::getFreeCatalog(Languages lang)
|
||||
{
|
||||
|
||||
if (lang >= LANG_COUNT) {
|
||||
//printf("[LanguageManager::getFreeCatalog] invalid language: %d\n", lang);
|
||||
mLogging.error("[LanguageManager::getFreeCatalog] invalid language: %d", lang);
|
||||
return nullptr;
|
||||
}
|
||||
lock();
|
||||
if (mFreeCatalogs[lang].size() > 0) {
|
||||
auto result = mFreeCatalogs[lang].back();
|
||||
result->duplicate();
|
||||
mFreeCatalogs[lang].pop_back();
|
||||
unlock();
|
||||
return result;
|
||||
}
|
||||
Poco::AutoPtr<LanguageCatalog> result = new LanguageCatalog(lang);
|
||||
return result;
|
||||
}
|
||||
95
src/cpp/SingletonManager/LanguageManager.h
Normal file
95
src/cpp/SingletonManager/LanguageManager.h
Normal file
@ -0,0 +1,95 @@
|
||||
/*!
|
||||
*
|
||||
* \author: einhornimmond
|
||||
*
|
||||
* \date: 13.11.19
|
||||
*
|
||||
* \brief: manage language translations with help of spirit_po
|
||||
*/
|
||||
|
||||
#ifndef GRADIDO_LOGIN_SERVER_SINGLETON_MANAGER_LANGUAGE_MANAGER_H
|
||||
#define GRADIDO_LOGIN_SERVER_SINGLETON_MANAGER_LANGUAGE_MANAGER_H
|
||||
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Logger.h"
|
||||
|
||||
#include "../lib/MultithreadContainer.h"
|
||||
#include <spirit_po/spirit_po.hpp>
|
||||
#include <list>
|
||||
|
||||
|
||||
enum Languages {
|
||||
LANG_DE,
|
||||
LANG_EN,
|
||||
LANG_COUNT
|
||||
};
|
||||
|
||||
class LanguageCatalog : protected UniLib::lib::MultithreadContainer
|
||||
{
|
||||
|
||||
public:
|
||||
LanguageCatalog(Languages lang);
|
||||
~LanguageCatalog();
|
||||
|
||||
// for poco auto ptr
|
||||
void duplicate() { lock(); mReferenceCount++; unlock(); };
|
||||
void release();
|
||||
|
||||
// catalog overload api
|
||||
|
||||
inline const char * gettext(const char * msgid) { return mCatalog->gettext(msgid); }
|
||||
inline const char * ngettext(const char * msgid, const char * msgid_plural, spirit_po::uint plural) {
|
||||
return mCatalog->ngettext(msgid, msgid_plural, plural);
|
||||
}
|
||||
inline const char * pgettext(const char * msgctxt, const char * msgid) {
|
||||
return mCatalog->pgettext(msgctxt, msgid);
|
||||
}
|
||||
inline const char * npgettext(const char * msgctxt, const char * msgid, const char * msgid_plural, spirit_po::uint plural) {
|
||||
return mCatalog->npgettext(msgctxt, msgid, msgid_plural, plural);
|
||||
}
|
||||
|
||||
inline std::string gettext_str(const std::string & msgid) { return mCatalog->gettext_str(msgid); }
|
||||
inline std::string ngettext_str(const std::string & msgid, const std::string & msgid_plural, spirit_po::uint plural) {
|
||||
return mCatalog->ngettext_str(msgid, msgid_plural, plural);
|
||||
}
|
||||
inline std::string pgettext_str(const std::string & msgctxt, const std::string & msgid) {
|
||||
return mCatalog->pgettext_str(msgctxt, msgid);
|
||||
}
|
||||
inline std::string npgettext_str(const std::string & msgctxt, const std::string & msgid, const std::string & msgid_plural, spirit_po::uint plural) {
|
||||
return mCatalog->npgettext_str(msgctxt, msgid, msgid_plural, plural);
|
||||
}
|
||||
|
||||
inline Languages getLanguage() { return mThisLanguage; }
|
||||
|
||||
protected:
|
||||
int mReferenceCount;
|
||||
spirit_po::default_catalog* mCatalog;
|
||||
Languages mThisLanguage;
|
||||
};
|
||||
|
||||
class LanguageManager : protected UniLib::lib::MultithreadContainer
|
||||
{
|
||||
friend class LanguageCatalog;
|
||||
public:
|
||||
~LanguageManager();
|
||||
|
||||
static LanguageManager* getInstance();
|
||||
|
||||
Poco::AutoPtr<LanguageCatalog> getFreeCatalog(Languages lang);
|
||||
|
||||
|
||||
protected:
|
||||
LanguageManager();
|
||||
|
||||
void returnCatalog(LanguageCatalog* catalog);
|
||||
|
||||
std::list<LanguageCatalog*> mFreeCatalogs[LANG_COUNT];
|
||||
|
||||
// poco logging
|
||||
Poco::Logger& mLogging;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //GRADIDO_LOGIN_SERVER_SINGLETON_MANAGER_LANGUAGE_MANAGER_H
|
||||
@ -7,7 +7,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline char *gettext (const char *__msgid)
|
||||
static inline const char *gettext (const char *__msgid)
|
||||
{
|
||||
return __msgid;
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ int SendErrorMessage::run()
|
||||
|
||||
|
||||
ErrorList::ErrorList()
|
||||
: mLogging(Poco::Logger::get("errorLog"))
|
||||
{
|
||||
|
||||
}
|
||||
@ -52,6 +53,9 @@ ErrorList::~ErrorList()
|
||||
|
||||
void ErrorList::addError(Error* error)
|
||||
{
|
||||
mLogging.error("[ErrorList::addError] error with function: %s, %s",
|
||||
std::string(error->getFunctionName()), std::string(error->getMessage())
|
||||
);
|
||||
mErrorStack.push(error);
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
#include "Poco/Net/SecureSMTPClientSession.h"
|
||||
#include "Poco/Net/StringPartSource.h"
|
||||
#include "Poco/Logger.h"
|
||||
|
||||
class ErrorList : public IErrorCollection
|
||||
{
|
||||
@ -47,6 +48,8 @@ public:
|
||||
|
||||
protected:
|
||||
std::stack<Error*> mErrorStack;
|
||||
// poco logging
|
||||
Poco::Logger& mLogging;
|
||||
};
|
||||
|
||||
class SendErrorMessage : public UniLib::controller::CPUTask
|
||||
|
||||
@ -16,6 +16,8 @@ int main(int argc, char** argv)
|
||||
}
|
||||
printf("User size: %d Bytes, Session size: %d Bytes\n", sizeof(User), sizeof(Session));
|
||||
|
||||
|
||||
|
||||
Gradido_LoginServer app;
|
||||
return app.run(argc, argv);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user