From ff6b859c52ad670b3db08e11209dc6833e894611 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 20 Jun 2015 16:44:57 +0200 Subject: o Adding app_name to app, creating a per-app logger. --- apps/apps.h | 9 +++++++++ apps/sample-add-timestamp.cpp | 4 ++++ apps/sample-convert.cpp | 5 +++++ apps/sample-select.cpp | 5 +++++ apps/sm-get-value.cpp | 10 +++++++--- apps/sm-serial-read-all.cpp | 5 +++++ apps/sm-serial-read.cpp | 5 +++++ 7 files changed, 40 insertions(+), 3 deletions(-) (limited to 'apps') 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 +#include +#include 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()->required(), "MAC of device to poll") ("sensor", po::value>(&sensors)->multitoken(), "Sensor to poll, defaults to all") ("sleep", po::value(&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 &&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") -- cgit v1.2.3