aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-06-20 16:44:57 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-06-20 16:44:57 +0200
commitff6b859c52ad670b3db08e11209dc6833e894611 (patch)
tree694d60baf29854c0c26e98f5db134526613a3b55
parentc7221b3666badbcf016e33997449e74778d979a9 (diff)
downloadble-toys-ff6b859c52ad670b3db08e11209dc6833e894611.tar.gz
ble-toys-ff6b859c52ad670b3db08e11209dc6833e894611.tar.bz2
ble-toys-ff6b859c52ad670b3db08e11209dc6833e894611.tar.xz
ble-toys-ff6b859c52ad670b3db08e11209dc6833e894611.zip
o Adding app_name to app, creating a per-app logger.
-rw-r--r--apps/apps.h9
-rw-r--r--apps/sample-add-timestamp.cpp4
-rw-r--r--apps/sample-convert.cpp5
-rw-r--r--apps/sample-select.cpp5
-rw-r--r--apps/sm-get-value.cpp10
-rw-r--r--apps/sm-serial-read-all.cpp5
-rw-r--r--apps/sm-serial-read.cpp5
7 files changed, 40 insertions, 3 deletions
diff --git a/apps/apps.h b/apps/apps.h
index 727e554..8173c51 100644
--- a/apps/apps.h
+++ b/apps/apps.h
@@ -1,6 +1,8 @@
#pragma once
#include <boost/program_options.hpp>
+#include <log4cplus/logger.h>
+#include <log4cplus/loggingmacros.h>
namespace trygvis {
namespace apps {
@@ -20,6 +22,9 @@ public:
class app {
public:
+ app(std::string app_name): _app_name(app_name), logger(log4cplus::Logger::getInstance(LOG4CPLUS_TEXT(app_name))) {
+ }
+ virtual ~app() = default;
virtual void add_options(po::options_description_easy_init &options) {
};
@@ -28,6 +33,10 @@ public:
};
virtual int main(app_execution &execution) = 0;
+
+protected:
+ const std::string _app_name;
+ const log4cplus::Logger logger;
};
int launch_app(int argc, char *argv[], app &app);
diff --git a/apps/sample-add-timestamp.cpp b/apps/sample-add-timestamp.cpp
index dbf24a1..22d81a6 100644
--- a/apps/sample-add-timestamp.cpp
+++ b/apps/sample-add-timestamp.cpp
@@ -50,6 +50,10 @@ private:
sample_format_type output_format;
public:
+ sample_add_timestamp() : app("sample-add-timestamp") {
+ }
+ ~sample_add_timestamp() = default;
+
void add_options(po::options_description_easy_init &options) override {
options
("help", "produce this help message")
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp
index baa1447..2dc34b3 100644
--- a/apps/sample-convert.cpp
+++ b/apps/sample-convert.cpp
@@ -26,6 +26,11 @@ private:
string table_name;
public:
+ sample_convert() : app("sample-convert") {
+ }
+
+ ~sample_convert() = default;
+
void add_options(po::options_description_easy_init &options) override {
options
("help", "produce this help message")
diff --git a/apps/sample-select.cpp b/apps/sample-select.cpp
index e1bac07..c4304da 100644
--- a/apps/sample-select.cpp
+++ b/apps/sample-select.cpp
@@ -17,6 +17,11 @@ private:
string fields;
public:
+ sample_select() : app("sample-select") {
+ }
+
+ ~sample_select() = default;
+
void add_options(po::options_description_easy_init &options) override {
options
("help", "produce this help message")
diff --git a/apps/sm-get-value.cpp b/apps/sm-get-value.cpp
index 115c6ae..b813121 100644
--- a/apps/sm-get-value.cpp
+++ b/apps/sm-get-value.cpp
@@ -87,9 +87,13 @@ namespace apps {
class sm_get_value : public app {
public:
+ sm_get_value() : app("sm-get-value") {
+ }
+
+ ~sm_get_value() = default;
+
void add_options(po::options_description_easy_init &options) override {
- options
- ("help", "produce help message")
+ options("help", "produce help message")
("device", po::value<string>()->required(), "MAC of device to poll")
("sensor", po::value<vector<unsigned int>>(&sensors)->multitoken(), "Sensor to poll, defaults to all")
("sleep", po::value<unsigned int>(&sleepTime)->default_value(0),
@@ -123,7 +127,7 @@ public:
loop = sleepTime > 0;
do {
- cout << "Connecting to device: " << device.getMac().str() << endl;
+ LOG4CPLUS_INFO(logger, "Connecting to device: " + device.getMac().str());
auto &gatt = device.connectGatt();
try {
diff --git a/apps/sm-serial-read-all.cpp b/apps/sm-serial-read-all.cpp
index 5c2af1d..5fa3f79 100644
--- a/apps/sm-serial-read-all.cpp
+++ b/apps/sm-serial-read-all.cpp
@@ -89,6 +89,11 @@ vector<string> &&find_ports() {
class sm_serial_read_all : public app {
public:
+ sm_serial_read_all() : app("sm-serial-read-all") {
+ }
+
+ ~sm_serial_read_all() = default;
+
bool run = true;
void add_options(po::options_description_easy_init &options) override {
diff --git a/apps/sm-serial-read.cpp b/apps/sm-serial-read.cpp
index 8a6fd36..8c4c299 100644
--- a/apps/sm-serial-read.cpp
+++ b/apps/sm-serial-read.cpp
@@ -54,6 +54,11 @@ private:
class sm_serial_read : public app {
public:
+ sm_serial_read() : app("sm-serial-read") {
+ }
+
+ ~sm_serial_read() = default;
+
void add_options(po::options_description_easy_init &options) override {
options
("help", "produce help message")