Completely removed logging
This commit is contained in:
parent
7271aa2cb0
commit
db4b8e8c81
2
Makefile
2
Makefile
|
@ -18,7 +18,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
objects = main.o udpTracker.o database.o driver_sqlite.o \
|
objects = main.o udpTracker.o database.o driver_sqlite.o \
|
||||||
tools.o httpserver.o webapp.o logging.o tracker.o
|
tools.o httpserver.o webapp.o tracker.o
|
||||||
target = udpt
|
target = udpt
|
||||||
|
|
||||||
%.o: src/%.c
|
%.o: src/%.c
|
||||||
|
|
|
@ -26,9 +26,6 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring> // memcpy
|
#include <cstring> // memcpy
|
||||||
#include "../multiplatform.h"
|
#include "../multiplatform.h"
|
||||||
#include "../logging.h"
|
|
||||||
|
|
||||||
extern UDPT::Logger *logger;
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -180,8 +177,6 @@ namespace UDPT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%d Clients Dumped.\n", i);
|
|
||||||
|
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
|
||||||
*max_count = i;
|
*max_count = i;
|
||||||
|
@ -259,7 +254,6 @@ namespace UDPT
|
||||||
|
|
||||||
// create table.
|
// create table.
|
||||||
r = sqlite3_exec(this->db, sql.c_str(), NULL, NULL, &err_msg);
|
r = sqlite3_exec(this->db, sql.c_str(), NULL, NULL, &err_msg);
|
||||||
printf("E:%s\n", err_msg);
|
|
||||||
|
|
||||||
return (r == SQLITE_OK);
|
return (r == SQLITE_OK);
|
||||||
}
|
}
|
||||||
|
@ -310,11 +304,7 @@ namespace UDPT
|
||||||
|
|
||||||
if (sqlite3_errcode(this->db) != SQLITE_OK)
|
if (sqlite3_errcode(this->db) != SQLITE_OK)
|
||||||
{
|
{
|
||||||
string str;
|
// TODO: Log this error
|
||||||
str = "[";
|
|
||||||
str += sqlite3_errmsg(this->db);
|
|
||||||
str += "]";
|
|
||||||
logger->log(Logger::LL_ERROR, str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int seeders = 0, leechers = 0;
|
int seeders = 0, leechers = 0;
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2012-2016 Naim A.
|
|
||||||
*
|
|
||||||
* This file is part of UDPT.
|
|
||||||
*
|
|
||||||
* UDPT 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.
|
|
||||||
*
|
|
||||||
* UDPT 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 UDPT. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "logging.h"
|
|
||||||
#include <fstream>
|
|
||||||
#include <ostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace UDPT {
|
|
||||||
|
|
||||||
Logger::Logger(const boost::program_options::variables_map& s)
|
|
||||||
: m_logfile (std::cout)
|
|
||||||
{
|
|
||||||
const std::string& filename = s["logging.filename"].as<std::string>();
|
|
||||||
const std::string& level = s["logging.level"].as<std::string>();
|
|
||||||
|
|
||||||
closeStreamOnDestroy = false;
|
|
||||||
|
|
||||||
if (level == "debug" || level == "d")
|
|
||||||
this->loglevel = LL_DEBUG;
|
|
||||||
else if (level == "warning" || level == "w")
|
|
||||||
this->loglevel = LL_WARNING;
|
|
||||||
else if (level == "info" || level == "i")
|
|
||||||
this->loglevel = LL_INFO;
|
|
||||||
else
|
|
||||||
this->loglevel = LL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger::~Logger()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::log(enum LogLevel lvl, string msg)
|
|
||||||
{
|
|
||||||
const char letters[] = "EWID";
|
|
||||||
if (lvl <= this->loglevel)
|
|
||||||
{
|
|
||||||
m_logfile << time (NULL) << ": ("
|
|
||||||
<< ((char)letters[lvl]) << "): "
|
|
||||||
<< msg << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2012-2016 Naim A.
|
|
||||||
*
|
|
||||||
* This file is part of UDPT.
|
|
||||||
*
|
|
||||||
* UDPT 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.
|
|
||||||
*
|
|
||||||
* UDPT 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 UDPT. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LOGGING_H_
|
|
||||||
#define LOGGING_H_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <queue>
|
|
||||||
#include <time.h>
|
|
||||||
#include <boost/program_options.hpp>
|
|
||||||
|
|
||||||
namespace UDPT {
|
|
||||||
class Logger
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum LogLevel {
|
|
||||||
LL_ERROR = 0,
|
|
||||||
LL_WARNING = 1,
|
|
||||||
LL_INFO = 2,
|
|
||||||
LL_DEBUG = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
Logger(const boost::program_options::variables_map& s);
|
|
||||||
|
|
||||||
virtual ~Logger();
|
|
||||||
|
|
||||||
void log(enum LogLevel, std::string msg);
|
|
||||||
private:
|
|
||||||
std::ostream& m_logfile;
|
|
||||||
enum LogLevel loglevel;
|
|
||||||
bool closeStreamOnDestroy;
|
|
||||||
|
|
||||||
static void setStream(Logger *logger, std::ostream &s);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* LOGGING_H_ */
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -25,7 +25,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
#include "logging.h"
|
|
||||||
#include "multiplatform.h"
|
#include "multiplatform.h"
|
||||||
#include "udpTracker.hpp"
|
#include "udpTracker.hpp"
|
||||||
#include "http/httpserver.hpp"
|
#include "http/httpserver.hpp"
|
||||||
|
@ -33,8 +32,6 @@
|
||||||
#include "tracker.hpp"
|
#include "tracker.hpp"
|
||||||
#include "service.hpp"
|
#include "service.hpp"
|
||||||
|
|
||||||
UDPT::Logger *logger = NULL;
|
|
||||||
|
|
||||||
static void _signal_handler(int sig)
|
static void _signal_handler(int sig)
|
||||||
{
|
{
|
||||||
switch (sig)
|
switch (sig)
|
||||||
|
@ -165,18 +162,6 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<UDPT::Logger> spLogger;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
spLogger = std::shared_ptr<UDPT::Logger>(new UDPT::Logger(var_map));
|
|
||||||
logger = spLogger.get();
|
|
||||||
}
|
|
||||||
catch (const std::exception& ex)
|
|
||||||
{
|
|
||||||
std::cerr << "Failed to initialize logger: " << ex.what() << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
if (!var_map.count("interactive"))
|
if (!var_map.count("interactive"))
|
||||||
{
|
{
|
||||||
|
@ -229,7 +214,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (ERROR_FAILED_SERVICE_CONTROLLER_CONNECT != err.getErrorCode())
|
if (ERROR_FAILED_SERVICE_CONTROLLER_CONNECT != err.getErrorCode())
|
||||||
{
|
{
|
||||||
logger->log(UDPT::Logger::LL_ERROR, "failed to start as service");
|
// TODO: log this error and exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
#include "logging.h"
|
|
||||||
#include "multiplatform.h"
|
#include "multiplatform.h"
|
||||||
#include "udpTracker.hpp"
|
#include "udpTracker.hpp"
|
||||||
#include "http/httpserver.hpp"
|
#include "http/httpserver.hpp"
|
||||||
|
|
|
@ -26,9 +26,7 @@
|
||||||
#include "udpTracker.hpp"
|
#include "udpTracker.hpp"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "multiplatform.h"
|
#include "multiplatform.h"
|
||||||
#include "logging.h"
|
|
||||||
|
|
||||||
extern UDPT::Logger *logger;
|
|
||||||
|
|
||||||
using namespace UDPT::Data;
|
using namespace UDPT::Data;
|
||||||
|
|
||||||
|
@ -115,7 +113,6 @@ namespace UDPT
|
||||||
|
|
||||||
ss.str("");
|
ss.str("");
|
||||||
ss << "Starting maintenance thread (1/" << ((int)this->m_threadCount) << ")";
|
ss << "Starting maintenance thread (1/" << ((int)this->m_threadCount) << ")";
|
||||||
logger->log(Logger::LL_INFO, ss.str());
|
|
||||||
|
|
||||||
// create maintainer thread.
|
// create maintainer thread.
|
||||||
|
|
||||||
|
@ -123,10 +120,6 @@ namespace UDPT
|
||||||
|
|
||||||
for (i = 1;i < this->m_threadCount; i++)
|
for (i = 1;i < this->m_threadCount; i++)
|
||||||
{
|
{
|
||||||
ss.str("");
|
|
||||||
ss << "Starting thread (" << (i + 1) << "/" << ((int)this->m_threadCount) << ")";
|
|
||||||
logger->log(Logger::LL_INFO, ss.str());
|
|
||||||
|
|
||||||
m_threads.push_back(boost::thread(UDPTracker::_thread_start, this));
|
m_threads.push_back(boost::thread(UDPTracker::_thread_start, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,6 @@
|
||||||
<ClCompile Include="..\..\src\db\driver_sqlite.cpp" />
|
<ClCompile Include="..\..\src\db\driver_sqlite.cpp" />
|
||||||
<ClCompile Include="..\..\src\http\httpserver.cpp" />
|
<ClCompile Include="..\..\src\http\httpserver.cpp" />
|
||||||
<ClCompile Include="..\..\src\http\webapp.cpp" />
|
<ClCompile Include="..\..\src\http\webapp.cpp" />
|
||||||
<ClCompile Include="..\..\src\logging.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\main.cpp" />
|
<ClCompile Include="..\..\src\main.cpp" />
|
||||||
<ClCompile Include="..\..\src\service.cpp" />
|
<ClCompile Include="..\..\src\service.cpp" />
|
||||||
<ClCompile Include="..\..\src\tools.c" />
|
<ClCompile Include="..\..\src\tools.c" />
|
||||||
|
@ -98,7 +97,6 @@
|
||||||
<ClInclude Include="..\..\src\exceptions.h" />
|
<ClInclude Include="..\..\src\exceptions.h" />
|
||||||
<ClInclude Include="..\..\src\http\httpserver.hpp" />
|
<ClInclude Include="..\..\src\http\httpserver.hpp" />
|
||||||
<ClInclude Include="..\..\src\http\webapp.hpp" />
|
<ClInclude Include="..\..\src\http\webapp.hpp" />
|
||||||
<ClInclude Include="..\..\src\logging.h" />
|
|
||||||
<ClInclude Include="..\..\src\multiplatform.h" />
|
<ClInclude Include="..\..\src\multiplatform.h" />
|
||||||
<ClInclude Include="..\..\src\service.hpp" />
|
<ClInclude Include="..\..\src\service.hpp" />
|
||||||
<ClInclude Include="..\..\src\tools.h" />
|
<ClInclude Include="..\..\src\tools.h" />
|
||||||
|
|
|
@ -27,9 +27,6 @@
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\logging.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\main.cpp">
|
<ClCompile Include="..\..\src\main.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -59,9 +56,6 @@
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\logging.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\multiplatform.h">
|
<ClInclude Include="..\..\src\multiplatform.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
Loading…
Reference in a new issue