Added ability to log warnings to external program defined via config.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Thu, 27 Aug 2009 16:03:35 +0000 (18:03 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Thu, 27 Aug 2009 16:03:35 +0000 (18:03 +0200)
src/config.cpp
src/config.h
src/logger.cpp
src/logger.h
src/updater.cpp

index ab55b22..bcb5130 100644 (file)
@@ -38,6 +38,8 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
     , EnableIPv6(false)
     , Loglevel(0)
     , ConfigPath("/etc/bpdyndnsd")
+    , ExternalWarningLog("")
+    , ExternalWarningLevel(0)
 {
     // initialize Logger
     Log = _log;
@@ -76,6 +78,8 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
         ("webcheck_url_alt",po::value<string>()->default_value(""),"Use this alternative URL to determine IP.")
         ("http_proxy",po::value<string>(),"Use this proxy for all http requests.")
         ("http_proxy_port",po::value<int>(),"Port of the proxy.")
+        ("external_warning_log",po::value<string>()->default_value(""),"External programm to pass warning log messages to.")
+        ("external_warning_level",po::value<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
     ;
 
     // Define valid command line parameters
@@ -213,6 +217,11 @@ int Config::parse_cmd_line(int argc, char *argv[])
             return -1;
         }
 
+        if ( VariablesMap.count("external_warning_log") )
+            ExternalWarningLog = VariablesMap["external_warning_log"].as<string>();
+
+        if ( VariablesMap.count("external_warning_level") )
+            ExternalWarningLevel = VariablesMap["external_warning_level"].as<int>();
 
     }
     catch(po::unknown_option e)
@@ -390,6 +399,12 @@ int Config::load_main_config_file(const string& full_filename)
                 return -1;
             }
 
+            if ( VariablesMap.count("external_warning_log") )
+                ExternalWarningLog = VariablesMap["external_warning_log"].as<string>();
+
+            if ( VariablesMap.count("external_warning_level") )
+                ExternalWarningLevel = VariablesMap["external_warning_level"].as<int>();
+
         }
         catch ( po::unknown_option e )      // at the moment 04-08-2009 this exception is never thrown :-(
         {
@@ -576,3 +591,24 @@ int Config::get_proxy_port() const
 {
     return ProxyPort;
 }
+
+
+/**
+ * Get member ExternalWarningLog
+ * @return ExternalWarningLog
+ */
+string Config::get_external_warning_log() const
+{
+    return ExternalWarningLog;
+}
+
+
+/**
+ * Get member ExternalWarningLevel
+ * @return ExternalWaringLevel
+ */
+int Config::get_external_warning_level() const
+{
+    return ExternalWarningLevel;
+}
+
index a33f8c0..5fdac70 100644 (file)
@@ -42,6 +42,8 @@ private:
     std::string WebcheckIpUrlAlt;
     std::string Proxy;
     int ProxyPort;
+    std::string ExternalWarningLog;
+    int ExternalWarningLevel;
 
     Service::Ptr create_service(const std::string &protocol,const std::string &hostname, const std::string &login, const std::string &password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl);
     int load_main_config_file(const std::string& full_filename);
@@ -83,6 +85,10 @@ public:
 
     void delete_variables_map();
 
+    int get_external_warning_level() const;
+
+    std::string get_external_warning_log() const;
+
 };
 
 #endif
index a94c784..293c397 100644 (file)
@@ -25,8 +25,10 @@ using namespace std;
 Logger::Logger()
     : Loglevel(0)
     , Syslog(false)
+    , ExternalWarningLog("")
+    , ExternalWarningLevel(0)
 {
-    set_log_facility(Loglevel,Syslog);
+    set_log_facility(Loglevel,Syslog,ExternalWarningLog,ExternalWarningLevel);
 }
 
 
@@ -42,7 +44,7 @@ Logger::~Logger()
  * Decides if Logging through syslog if enabled or through std.
  * @param msg The message to log.
  */
-void Logger::log_notice(const string& msg) const
+void Logger::log_notice(const string& msg, int level) const
 {
     if ( Syslog )
         syslog(LOG_NOTICE,msg.c_str());
@@ -55,12 +57,20 @@ void Logger::log_notice(const string& msg) const
  * Decides if Logging through syslog if enabled or through std.
  * @param msg The message to log.
  */
-void Logger::log_warning(const string& msg) const
+void Logger::log_warning(const string& msg, int level) const
 {
     if ( Syslog )
         syslog(LOG_WARNING,msg.c_str());
     else
         cout << msg << endl;
+
+    if ( (level <= ExternalWarningLevel) && (!ExternalWarningLog.empty()) )
+    {
+        string external = ExternalWarningLog;
+        external.append(" ");
+        external.append(msg);
+        int ret_val = system(external.c_str());
+    }
 }
 
 
@@ -68,7 +78,7 @@ void Logger::log_warning(const string& msg) const
  * Decides if Logging through syslog if enabled or through std.
  * @param msg The message to log.
  */
-void Logger::log_error(const string& msg) const
+void Logger::log_error(const string& msg, int level) const
 {
     if ( Syslog )
         syslog(LOG_ERR,msg.c_str());
@@ -121,10 +131,13 @@ bool Logger::get_syslog() const
 /**
  * Initialize the logging facility.
  */
-void Logger::set_log_facility(const int _loglevel, const bool _syslog)
+void Logger::set_log_facility(const int _loglevel, const bool _syslog, const string& _external_error_log, const int _external_error_level)
 {
     Loglevel = _loglevel;
     Syslog = _syslog;
+    ExternalWarningLog = _external_error_log;
+    ExternalWarningLevel = _external_error_level;
+
 
     if ( Syslog )
         openlog("bpdyndnsd",LOG_PID,LOG_DAEMON);
@@ -136,12 +149,13 @@ void Logger::set_log_facility(const int _loglevel, const bool _syslog)
  */
 void Logger::print_usage(const Options_descriptionPtr opt_desc) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl;
         msg << *opt_desc << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -152,11 +166,12 @@ void Logger::print_usage(const Options_descriptionPtr opt_desc) const
  */
 void Logger::print_version() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << VERSION << "." << REVISION << "." << RELEASE << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -166,22 +181,24 @@ void Logger::print_version() const
  */
 void Logger::print_cmd_parsed() const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Command line options successfully parsed." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
 
 void Logger::print_conf_files_parsed() const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Config files successfully parsed." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -192,11 +209,12 @@ void Logger::print_conf_files_parsed() const
  */
 void Logger::print_conf_loaded(const string& config_path) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Config files successfully loaded in: " << config_path << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -207,11 +225,12 @@ void Logger::print_conf_loaded(const string& config_path) const
  */
 void Logger::print_conf_not_loaded(const string& config_path) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Config files couldn't be loaded in: " << config_path << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -222,11 +241,12 @@ void Logger::print_conf_not_loaded(const string& config_path) const
  */
 void Logger::print_error_opening_r(const string& filename) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Error opening file for reading: " << filename << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -237,11 +257,12 @@ void Logger::print_error_opening_r(const string& filename) const
  */
 void Logger::print_error_opening_rw(const string& filename) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Error opening file for writing: " << filename << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -252,11 +273,12 @@ void Logger::print_error_opening_rw(const string& filename) const
  */
 void Logger::print_destructor_call(const string& _class) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Destructor call: " << _class << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -267,11 +289,12 @@ void Logger::print_destructor_call(const string& _class) const
  */
 void Logger::print_constructor_call(const string& _class) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Constructor call: " << _class << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -282,11 +305,12 @@ void Logger::print_constructor_call(const string& _class) const
  */
 void Logger::print_update_service(const string& service) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Running update for service: " << service << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -297,11 +321,12 @@ void Logger::print_update_service(const string& service) const
  */
 void Logger::print_unknown_cmd_option(const string& unknown_option) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Unknown option on command line detected: " << unknown_option << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -312,11 +337,12 @@ void Logger::print_unknown_cmd_option(const string& unknown_option) const
  */
 void Logger::print_unknown_protocol(const string& protocol) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Unknown protocol defined: " << protocol << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -327,11 +353,12 @@ void Logger::print_unknown_protocol(const string& protocol) const
  */
 void Logger::print_load_service_conf(const string& filename) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Loading service config file: " << filename << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -342,11 +369,12 @@ void Logger::print_load_service_conf(const string& filename) const
  */
 void Logger::print_load_main_conf(const string& filename) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Loading main config file: " << filename << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -357,11 +385,12 @@ void Logger::print_load_main_conf(const string& filename) const
  */
 void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -372,11 +401,12 @@ void Logger::print_unknown_service_conf_option(const string& service_conf_file,
  */
 void Logger::print_unknown_main_conf_option(const string& unknown_option) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Unknown option in main config file detected: " << unknown_option << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -387,11 +417,12 @@ void Logger::print_unknown_main_conf_option(const string& unknown_option) const
  */
 void Logger::print_error_config_path(const string& config_path) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Config path doesn't exists or is not a diretory: " << config_path << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -401,11 +432,12 @@ void Logger::print_error_config_path(const string& config_path) const
  */
 void Logger::print_missing_cmd_service_option() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Missing option to initialize service. Protocol, host, login and password must be specified." << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -416,11 +448,12 @@ void Logger::print_missing_cmd_service_option() const
  */
 void Logger::print_missing_service_conf_option(const string& service_conf_file) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -431,11 +464,12 @@ void Logger::print_missing_service_conf_option(const string& service_conf_file)
  */
 void Logger::print_runnig_as_daemon(const int pid) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Runnig as daemon: " << pid << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -446,14 +480,15 @@ void Logger::print_runnig_as_daemon(const int pid) const
  */
 void Logger::print_daemon_mode(const bool daemon_mode) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         string mode = "disabled";
         if (daemon_mode == true)
             mode = "enabled";
         ostringstream msg;
         msg << "Daemon mode is " << mode << "." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -463,11 +498,12 @@ void Logger::print_daemon_mode(const bool daemon_mode) const
  */
 void Logger::print_error_fork() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Error while trying to fork." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -478,11 +514,12 @@ void Logger::print_error_fork() const
  */
 void Logger::print_pid_found(const int pid) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -493,11 +530,12 @@ void Logger::print_pid_found(const int pid) const
  */
 void Logger::print_process_already_running(const int pid) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -507,11 +545,12 @@ void Logger::print_process_already_running(const int pid) const
  */
 void Logger::print_caught_sigterm() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Caught SIGTERM. Exiting..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -521,11 +560,12 @@ void Logger::print_caught_sigterm() const
  */
 void Logger::print_caught_siguser1() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Caught SIGUSR1. Switching to offline mode..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -535,11 +575,12 @@ void Logger::print_caught_siguser1() const
  */
 void Logger::print_caught_sighup() const
 {
-    if ( 0 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Caught SIGHUP. Reloading config and switching to online mode..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -549,11 +590,12 @@ void Logger::print_caught_sighup() const
  */
 void Logger::print_error_setting_signal(const string& signal) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Error while setting signal handler for: " << signal << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -563,11 +605,12 @@ void Logger::print_error_setting_signal(const string& signal) const
  */
 void Logger::print_init_log_facility() const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -577,11 +620,12 @@ void Logger::print_init_log_facility() const
  */
 void Logger::print_offline_mode() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Offline mode..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -591,11 +635,12 @@ void Logger::print_offline_mode() const
  */
 void Logger::print_serialized_objects_success() const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Serialized objects successfully." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -605,11 +650,12 @@ void Logger::print_serialized_objects_success() const
  */
 void Logger::print_deserialized_objects_success() const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "De-serialized objects successfully." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -626,7 +672,8 @@ void Logger::print_deserialized_objects_success() const
  */
 void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const string& actual_ip, list<int>* lastupdated) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << message << endl;
@@ -641,7 +688,7 @@ void Logger::print_service_object(const string& message, const string& protocol,
         {
             msg << "\t" << "Lastupdated:      " << update_time << endl;
         }
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -652,11 +699,12 @@ void Logger::print_service_object(const string& message, const string& protocol,
  */
 void Logger::print_exception_serialize(const string& exception) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Error while trying to serialize Serviceholder object: " << exception << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -667,11 +715,12 @@ void Logger::print_exception_serialize(const string& exception) const
  */
 void Logger::print_exception_deserialize(const string& exception) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Error while trying to de-serialize Serviceholder object: " << exception << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -682,11 +731,12 @@ void Logger::print_exception_deserialize(const string& exception) const
  */
 void Logger::print_error_kill_child(const int pid) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Could not kill child process with PID: " << pid << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -697,11 +747,12 @@ void Logger::print_error_kill_child(const int pid) const
  */
 void Logger::print_child_killed(const int pid) const
 {
-    if ( 0 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Killed child process with PID: " << pid << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -712,11 +763,12 @@ void Logger::print_child_killed(const int pid) const
  */
 void Logger::print_no_object_file(const string& object_file) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl;
-        log_warning(msg.str());
+        log_warning(msg.str(),level);
     }
 }
 
@@ -727,11 +779,12 @@ void Logger::print_no_object_file(const string& object_file) const
  */
 void Logger::print_hostname(const string& hostname) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Detected following hostname of localhost: " << hostname << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -742,11 +795,12 @@ void Logger::print_hostname(const string& hostname) const
  */
 void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -757,11 +811,12 @@ void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) co
  */
 void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -773,11 +828,12 @@ void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) co
  */
 void Logger::print_error_hostname_to_ip(const string& exception, const string& hostname) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << exception << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -788,11 +844,12 @@ void Logger::print_error_hostname_to_ip(const string& exception, const string& h
  */
 void Logger::print_update_service_successful(const string& service) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Updated service successful: " << service << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -802,11 +859,12 @@ void Logger::print_update_service_successful(const string& service) const
  */
 void Logger::print_webcheck_no_ip() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "This hosts' IP could not be determined through any configured webcheck url." << endl;
-        log_error(msg.str());
+        log_warning(msg.str(),level);
     }
 }
 
@@ -818,11 +876,12 @@ void Logger::print_webcheck_no_ip() const
  */
 void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
-        log_warning(msg.str());
+        log_warning(msg.str(),level);
     }
 }
 
@@ -834,11 +893,12 @@ void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, c
  */
 void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -849,11 +909,12 @@ void Logger::print_webcheck_error(const char * curl_err_buff, const string& url)
  */
 void Logger::print_received_curl_data(const string& curl_data) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Received CURL data: " << curl_data << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -864,11 +925,12 @@ void Logger::print_received_curl_data(const string& curl_data) const
  */
 void Logger::print_regex_found_ip(const string& ip) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Found IP-Address via regex: " << ip << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -879,11 +941,12 @@ void Logger::print_regex_found_ip(const string& ip) const
  */
 void Logger::print_regex_ip_not_found(const string& data) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl;
-        log_warning(msg.str());
+        log_warning(msg.str(),level);
     }
 }
 
@@ -894,11 +957,12 @@ void Logger::print_regex_ip_not_found(const string& data) const
  */
 void Logger::print_multiple_cmd_option(const string& message) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "The same option is only allowed once: " << message << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -912,11 +976,12 @@ void Logger::print_multiple_cmd_option(const string& message) const
  */
 void Logger::print_update_not_allowed(const int current_time, const int old_time, const int MaxUpdatesWithinInterval, const string& service) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Update not allowed for service: " << service << ". Too many updates within max update interval. Current time: " << current_time << ". Update time before " << MaxUpdatesWithinInterval << " updates: " << old_time << endl;
-        log_warning(msg.str());
+        log_warning(msg.str(),level);
     }
 }
 
@@ -927,11 +992,12 @@ void Logger::print_update_not_allowed(const int current_time, const int old_time
  */
 void Logger::print_update_service_failure(const string& service) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Could not update service: " << service << endl;
-        log_warning(msg.str());
+        log_warning(msg.str(),level);
     }
 }
 
@@ -941,11 +1007,12 @@ void Logger::print_update_service_failure(const string& service) const
  */
 void Logger::print_starting_shutdown() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Shutting down ..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -955,11 +1022,12 @@ void Logger::print_starting_shutdown() const
  */
 void Logger::print_shutdown_succeeded() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Shutting down complete ..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -969,11 +1037,12 @@ void Logger::print_shutdown_succeeded() const
  */
 void Logger::print_shutdown_parent_succeeded() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Shutting down parent process completed ..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -983,11 +1052,12 @@ void Logger::print_shutdown_parent_succeeded() const
  */
 void Logger::print_starting_shutdown_parent() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Shutting down parent process ..." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -1001,11 +1071,12 @@ void Logger::print_starting_shutdown_parent() const
  */
 void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "DNS cache record for host <" << hostname << "> expired: Lastupdated: " << lastupdated << " DNS cache ttl: " << dns_cache_ttl << " Current time: " << current_time << " Checking current DNS cache status." << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -1017,11 +1088,12 @@ void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdat
  */
 void Logger::print_cached_dns_entry(const string& hostname, const string& cached_dns_entry, const string& lastupdated_ip) const
 {
-    if ( 1 <= Loglevel )
+    int level = 1;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Cached DNS record for host <" << hostname << "> : " << cached_dns_entry << " Last updated IP: " << lastupdated_ip << endl;
-        log_notice(msg.str());
+        log_notice(msg.str(),level);
     }
 }
 
@@ -1031,11 +1103,12 @@ void Logger::print_cached_dns_entry(const string& hostname, const string& cached
  */
 void Logger::print_missing_cmd_proxy_option() const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Missing option to initialize proxy. http_proxy and http_proxy_port must be specified." << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -1047,11 +1120,12 @@ void Logger::print_missing_cmd_proxy_option() const
  */
 void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -1063,11 +1137,12 @@ void Logger::print_multiple_service_conf_option(const string& service_conf_file,
  */
 void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
 
@@ -1077,10 +1152,11 @@ void Logger::print_multiple_main_conf_option(const string& main_conf_file, const
  */
 void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const
 {
-    if ( 0 <= Loglevel )
+    int level = 0;
+    if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
     {
         ostringstream msg;
         msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl;
-        log_error(msg.str());
+        log_error(msg.str(),level);
     }
 }
index bba853f..75117e6 100644 (file)
@@ -24,6 +24,8 @@ private:
 
     int Loglevel;
     bool Syslog;
+    std::string ExternalWarningLog;
+    int ExternalWarningLevel;
 
 public:
 
@@ -33,11 +35,11 @@ public:
 
     ~Logger();
 
-    void log_notice(const std::string& msg) const;
+    void log_notice(const std::string& msg, int loglevel) const;
 
-    void log_warning(const std::string& msg) const;
+    void log_warning(const std::string& msg, int loglevel) const;
 
-    void log_error(const std::string& msg) const;
+    void log_error(const std::string& msg, int loglevel) const;
 
     void set_loglevel(const int _loglevel);
 
@@ -47,7 +49,7 @@ public:
 
     bool get_syslog() const;
 
-    void set_log_facility(const int _loglevel, const bool _syslog);
+    void set_log_facility(const int _loglevel, const bool _syslog, const std::string& _external_error_log, const int _external_error_level);
 
     void print_usage(const Options_descriptionPtr opt_desc) const;
 
index f25bc93..0f35a65 100644 (file)
@@ -163,7 +163,7 @@ int Updater::reload_config()
  */
 void Updater::init_log_facility()
 {
-    Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog());
+    Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog(),Conf->get_external_warning_log(),Conf->get_external_warning_level());
     Log->print_init_log_facility();
 }