Skip to content

Commit

Permalink
chore(DBLogger): style and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-f committed Nov 18, 2024
1 parent 04b3db1 commit d029667
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
46 changes: 23 additions & 23 deletions Data/samples/DBLogger/src/DBLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class DBLogger: public ServerApplication

using WorkSet = std::unordered_set<std::string>;

DBLogger()
{
Poco::Data::SQLite::Connector::registerConnector();
Poco::Data::SQLChannel::registerChannel();
}
DBLogger()
{
Poco::Data::SQLite::Connector::registerConnector();
Poco::Data::SQLChannel::registerChannel();
}

~DBLogger() override = default;

Expand All @@ -57,25 +57,25 @@ class DBLogger: public ServerApplication

const auto& cfg { config() };

if (!cfg.has("logging.channels.sql.directory"))
if (!cfg.has("logging.channels.sql.directory"))
{
throw Poco::Util::MissingOptionException ("Missing scanning directory.");
}
_inserter.setDirectory( cfg.getString("logging.channels.sql.directory") );
_inserter.setDirectory(cfg.getString("logging.channels.sql.directory") );

if (!cfg.has("DBLogger.connector"))
{
throw Poco::Util::MissingOptionException ("Missing database connector.");
}
_inserter.setConnector( cfg.getString("DBLogger.connector") );
_inserter.setConnector(cfg.getString("DBLogger.connector") );

if (!cfg.has("DBLogger.constring"))
{
throw Poco::Util::MissingOptionException ("Missing database connection string.");
}
_inserter.setConnectionString( cfg.getString("DBLogger.constring") );
_inserter.setConnectionString(cfg.getString("DBLogger.constring") );

_inserter.setNumWorkers( cfg.getUInt64("DBLogger.workers", 2) );
_inserter.setNumWorkers(cfg.getUInt64("DBLogger.workers", 2) );
_demoMessagesRequested = cfg.getBool("DBLogger.demo", false);

logger().information("Directory: %s", _inserter.directory());
Expand All @@ -84,14 +84,14 @@ class DBLogger: public ServerApplication

if (_demoMessagesRequested)
{
auto& dl = Poco::Logger::get("SQLDemo");
auto* sqlChannel = dynamic_cast<Poco::Data::SQLChannel*>(dl.getChannel().get());
if (sqlChannel == nullptr)
{
throw Poco::Util::UnexpectedArgumentException ("SQLDemo logger does not have SQL channel.");
}
auto& dl = Poco::Logger::get("SQLDemo");
auto* sqlChannel = dynamic_cast<Poco::Data::SQLChannel*>(dl.getChannel().get());
if (sqlChannel == nullptr)
{
throw Poco::Util::UnexpectedArgumentException ("SQLDemo logger does not have SQL channel.");
}

_tableName = cfg.getString("logging.channels.sql.table");
_tableName = cfg.getString("logging.channels.sql.table");

// Only delete and create table when creating demo messages
logger().information("Demo messages: Creating new table: %s", _tableName);
Expand Down Expand Up @@ -122,7 +122,7 @@ class DBLogger: public ServerApplication

if (_demoMessagesRequested)
{
_sqlSourceThread = std::move(std::thread(&DBLogger::createMessages, this));
_sqlSourceThread = std::thread(&DBLogger::createMessages, this);
logger().information("Started creating demo messages.");
}
}
Expand All @@ -135,7 +135,7 @@ class DBLogger: public ServerApplication
return;
}

logger().information("Request to stop processing.");
logger().information("Request to stop processing.");

if (_demoMessagesRequested)
{
Expand Down Expand Up @@ -180,7 +180,7 @@ class DBLogger: public ServerApplication
Option("dir", "d", "directory path to scan for SQL log files")
.repeatable(false)
.argument("dir")
.binding("logging.channels.sql.directory")
.binding("logging.channels.sql.directory")
);

options.addOption(
Expand Down Expand Up @@ -241,13 +241,13 @@ class DBLogger: public ServerApplication
void createMessages()
{
int i {0};
auto& dl = Poco::Logger::get("SQLDemo");
auto& dl = Poco::Logger::get("SQLDemo");

while (_active)
{
for (int j = 0; j < 100 && _active; ++j)
{
dl.debug("%d Informational message", i);
dl.debug("%d Informational message", i);
++i;
++_created;
}
Expand Down Expand Up @@ -278,7 +278,7 @@ class DBLogger: public ServerApplication

std::size_t _created{0};
std::thread _sqlSourceThread;
std::string _tableName{"T_POCO_LOG"};
std::string _tableName{"T_POCO_LOG"};
};


Expand Down
12 changes: 6 additions & 6 deletions Data/samples/DBLogger/src/SQLLogInserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#include <fstream>
#include <iostream>

using namespace Poco::Data::Keywords;

using namespace Poco::Data::Keywords;
using namespace std::string_literals;


void SQLLogInserter::start()
{
_dataSession = std::make_shared<Poco::Data::Session>(_connector, _connectionString);
Expand All @@ -41,9 +42,10 @@ void SQLLogInserter::start()
}

// Thread to scan the directory
_dirScanThread = std::move(std::thread(&SQLLogInserter::runDirectoryScan, this));
_dirScanThread = std::thread(&SQLLogInserter::runDirectoryScan, this);
}


void SQLLogInserter::stop()
{
_active = false;
Expand Down Expand Up @@ -71,7 +73,7 @@ void SQLLogInserter::stop()
}
}

_dataSession->close();
_dataSession->close();
}


Expand Down Expand Up @@ -230,7 +232,7 @@ void SQLLogInserter::runDirectoryScan()
if (!_active && !_doneProcessing)
{
// Last scan directory to clean up
(void)scanDirectory();
(void)scanDirectory();
_doneProcessing = true;
_workCondition.notify_all();
break;
Expand All @@ -253,5 +255,3 @@ void SQLLogInserter::runProcessingEntries()
}
_completedCondition.notify_all();
}


0 comments on commit d029667

Please sign in to comment.