Commit 7771e50f430be9fcaa5bf334c7bb6dabc348502b
1 parent
8310c84d
moved log.h to include and added log setters to mqttclient (default up to info )
Showing
6 changed files
with
42 additions
and
9 deletions
examples/pub/publisher.cpp
@@ -31,6 +31,9 @@ Publisher::Publisher() | @@ -31,6 +31,9 @@ Publisher::Publisher() | ||
31 | 31 | ||
32 | void Publisher::connect(const std::string &hostname, int portnumber, const std::string &username, const std::string &password, const std::string &lwt_topic, const std::string &lwt_message) | 32 | void Publisher::connect(const std::string &hostname, int portnumber, const std::string &username, const std::string &password, const std::string &lwt_topic, const std::string &lwt_message) |
33 | { | 33 | { |
34 | + m_mqtt_client.setLogLevel( osdev::components::log::LogLevel::Info ); | ||
35 | + m_mqtt_client.setMask( osdev::components::log::LogMask::Upto ); | ||
36 | + | ||
34 | m_mqtt_client.connect( hostname, portnumber, osdev::components::mqtt::Credentials( username, password ), osdev::components::mqtt::mqtt_LWT( lwt_topic, lwt_message ) ); | 37 | m_mqtt_client.connect( hostname, portnumber, osdev::components::mqtt::Credentials( username, password ), osdev::components::mqtt::mqtt_LWT( lwt_topic, lwt_message ) ); |
35 | std::cout << "Client state : " << m_mqtt_client.state() << std::endl; | 38 | std::cout << "Client state : " << m_mqtt_client.state() << std::endl; |
36 | } | 39 | } |
src/log.h renamed to include/log.h
include/mqttclient.h
@@ -31,12 +31,15 @@ | @@ -31,12 +31,15 @@ | ||
31 | #include <vector> | 31 | #include <vector> |
32 | 32 | ||
33 | // osdev::components::mqtt | 33 | // osdev::components::mqtt |
34 | -#include "synchronizedqueue.h" | ||
35 | -#include "istatecallback.h" | ||
36 | -#include "serverstate.h" | ||
37 | 34 | ||
35 | +#include "istatecallback.h" | ||
38 | #include "imqttclient.h" | 36 | #include "imqttclient.h" |
39 | #include "mqtt_lwt.h" | 37 | #include "mqtt_lwt.h" |
38 | +#include "serverstate.h" | ||
39 | +#include "synchronizedqueue.h" | ||
40 | + | ||
41 | +// osdev::components::logger | ||
42 | +#include "log.h" | ||
40 | 43 | ||
41 | namespace osdev { | 44 | namespace osdev { |
42 | namespace components { | 45 | namespace components { |
@@ -166,6 +169,22 @@ public: | @@ -166,6 +169,22 @@ public: | ||
166 | */ | 169 | */ |
167 | virtual std::string endpoint() const override; | 170 | virtual std::string endpoint() const override; |
168 | 171 | ||
172 | + /*! | ||
173 | + * \brief setMask update the current logMask | ||
174 | + * \param logMask - Enum defining the logmask used. | ||
175 | + */ | ||
176 | + void setMask ( osdev::components::log::LogMask logMask ); | ||
177 | + /*! | ||
178 | + * \brief setLogLevel update the current logLevel | ||
179 | + * \param logLevel - Enum defining the logLevel used, in combination with Mask. | ||
180 | + */ | ||
181 | + void setLogLevel( osdev::components::log::LogLevel logLevel ); | ||
182 | + /*! | ||
183 | + * \brief setContext update the current context | ||
184 | + * \param context - String containing the new context name. | ||
185 | + */ | ||
186 | + void setContext ( std::string context ); | ||
187 | + | ||
169 | private: | 188 | private: |
170 | /*! | 189 | /*! |
171 | * \brief Callback used to pick up the connection status of the wrappers. | 190 | * \brief Callback used to pick up the connection status of the wrappers. |
src/CMakeLists.txt
src/log.cpp
@@ -53,8 +53,8 @@ int toInt( LogLevel level ) | @@ -53,8 +53,8 @@ int toInt( LogLevel level ) | ||
53 | 53 | ||
54 | std::string Log::s_context = std::string(); | 54 | std::string Log::s_context = std::string(); |
55 | std::string Log::s_fileName = std::string(); | 55 | std::string Log::s_fileName = std::string(); |
56 | -LogLevel Log::s_logLevel = LogLevel::Debug; | ||
57 | -LogMask Log::s_logMask = LogMask::None; | 56 | +LogLevel Log::s_logLevel = LogLevel::Info; |
57 | +LogMask Log::s_logMask = LogMask::Upto; | ||
58 | 58 | ||
59 | void Log::init( const std::string& context, const std::string& logFile, LogLevel logDepth ) | 59 | void Log::init( const std::string& context, const std::string& logFile, LogLevel logDepth ) |
60 | { | 60 | { |
src/mqttclient.cpp
@@ -21,9 +21,6 @@ | @@ -21,9 +21,6 @@ | ||
21 | * ***************************************************************************/ | 21 | * ***************************************************************************/ |
22 | #include "mqttclient.h" | 22 | #include "mqttclient.h" |
23 | 23 | ||
24 | -// osdev::components::logger | ||
25 | -#include "log.h" | ||
26 | - | ||
27 | // osdev::components::mqtt | 24 | // osdev::components::mqtt |
28 | #include "clientpaho.h" | 25 | #include "clientpaho.h" |
29 | #include "mqttutil.h" | 26 | #include "mqttutil.h" |
@@ -613,3 +610,18 @@ void MqttClient::eventHandler() | @@ -613,3 +610,18 @@ void MqttClient::eventHandler() | ||
613 | } | 610 | } |
614 | LogInfo("[MqttClient::eventHandler]", std::string( m_clientId + " - leaving event handler." ) ); | 611 | LogInfo("[MqttClient::eventHandler]", std::string( m_clientId + " - leaving event handler." ) ); |
615 | } | 612 | } |
613 | + | ||
614 | +void MqttClient::setMask(log::LogMask logMask ) | ||
615 | +{ | ||
616 | + Log::setMask( logMask ); | ||
617 | +} | ||
618 | + | ||
619 | +void MqttClient::setLogLevel(log::LogLevel logLevel) | ||
620 | +{ | ||
621 | + Log::setLogLevel( logLevel ); | ||
622 | +} | ||
623 | + | ||
624 | +void MqttClient::setContext(std::string context) | ||
625 | +{ | ||
626 | + Log::setContext( context ); | ||
627 | +} |