The log level can be configured in the command line, through --log-level=<level>...
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 20 Feb 2012 18:11:17 +0000 (16:11 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 20 Feb 2012 18:11:17 +0000 (16:11 -0200)
Readme
src/main.cpp

diff --git a/Readme b/Readme
index 598d602..4c2a210 100644 (file)
--- a/Readme
+++ b/Readme
@@ -94,6 +94,8 @@ following:
 - config-file: command line to specify a file where the hosts and other
   configuration information are provided.
 - daemon: run the application as a daemon.
+- log-level: apply a filter of which log messages will be printed. The available
+  options are the default Unix levels (e.g. debug, info, etc.).
 
 
 
index 2dd0eef..2f7e85d 100644 (file)
@@ -32,6 +32,7 @@ on this file might be covered by the GNU General Public License.
 #include "config/configurationreader.h"
 #include "config/host.h"
 #include "link/linkstatus.h"
+#include "host/loglevel.h"
 #include "host/pingerfactory.h"
 #include "host/pingprotocol.h"
 #include "host/pingscheduler.h"
@@ -46,9 +47,6 @@ using I2n::Logger::GlobalLogger;
 // Declarations
 //-----------------------------------------------------------------------------
 
-// TODO: Change back to Notice log level
-const int default_log_level = I2n::Logger::LogLevel::Info;
-
 ConfigurationItem get_configuration(int, const char**);
 LinkStatusItem get_status_notifier(const ConfigurationItem&);
 void init_logger();
@@ -56,7 +54,7 @@ void init_pingers(const ConfigurationItem&, const LinkStatusItem&, PingScheduler
 void start_pingers(const PingSchedulerList&);
 void stop_pingers(const PingSchedulerList&);
 void block_all_signals();
-void handle_signals();
+void handle_signals(const int default_log_level);
 
 //-----------------------------------------------------------------------------
 // Definitions
@@ -102,6 +100,8 @@ LinkStatusItem get_status_notifier(
 
 void init_logger()
 {
+    const int default_log_level = I2n::Logger::LogLevel::Info;
+
     I2n::Logger::enable_syslog( I2n::Logger::Facility::User ); //lint !e1786
     I2n::Logger::set_log_level( default_log_level );           //lint !e534
 }
@@ -196,9 +196,11 @@ void block_all_signals()
 /**
  * @brief Wait until a signal receives and act upon it
  *
+ * @param default_log_level
+ *
  * @return void
  **/
-void handle_signals()
+void handle_signals( const int default_log_level )
 {
     // Wait for signals
     sigset_t all_signals;
@@ -249,6 +251,8 @@ int main( int argc, const char *argv[] )
     ConfigurationItem configuration = get_configuration( argc, argv );
     if ( configuration.get() != NULL )
     {
+        int log_level = configuration->get_log_level();
+        I2n::Logger::set_log_level( log_level );
 
         bool daemon_mode = configuration->get_daemon();
         if ( daemon_mode )
@@ -264,7 +268,7 @@ int main( int argc, const char *argv[] )
         start_pingers( scheduler_list );
 
         // React to signals (main thread will sleep)
-        handle_signals();
+        handle_signals( log_level );
 
         stop_pingers( scheduler_list );