Exemplo n.º 1
0
void Logger::setThresholdFromLoggingProperties(log4cplus::Logger logger) {
    // if logging.properties exists, attempt to set the
    // appropriate level for the given logger
    if (fileExists(PROP_FILE_LOC)) {
        Properties props(PROP_FILE_LOC);

        string loggerName = logger.getName();
        string logLevelKey = loggerName + ".level";
        if (props.isSet(logLevelKey)) {
            string level = props.get(logLevelKey);
            int l4cpLevel = log4cplus::getLogLevelManager().fromString(level);
            if (l4cpLevel != log4cplus::NOT_SET_LOG_LEVEL) {
                LOG4CPLUS_INFO(
                        logger,
                        LOG4CPLUS_TEXT(
                                "Configuring logger " + loggerName
                                + " with level " + level));
                logger.setLogLevel(l4cpLevel);
            } else {
                LOG4CPLUS_INFO(
                        logger,
                        LOG4CPLUS_TEXT(
                            "Unable to configure logger " + loggerName
                            + " with level " + level
                            + "; no such level found."));
            }
        }
    }
}
Exemplo n.º 2
0
//---------------------------------------------------------//
void  CServer::initialize_logger(log4cplus::Logger& my_logger, IniReader::Section& section)
{
	using namespace log4cplus;
	
	my_logger.removeAllAppenders();

	std::string log_pattern;
	section.get_value("LOG_PATTERN", log_pattern, "%D{%c} [%t] [%p]: %m%n");

	std::string log_file_name;
	section.get_value("LOG_FILE_NAME", log_file_name, "Server.log");

	long log_parts;
	section.get_value("LOG_PARTS", log_parts, 3);

	long log_file_size;
	section.get_value("LOG_FILE_SIZE", log_file_size, 100);

	long log_level;
	section.get_value("LOG_LEVEL", log_level, long(log4cplus::FATAL_LOG_LEVEL));

	SharedAppenderPtr appender(new RollingFileAppender(	log_file_name, 
														log_file_size * 1024 * 1024, 
														log_parts));
	appender->setName(_T("log_appender"));
	appender->setLayout(std::auto_ptr<Layout>(new PatternLayout(log_pattern)));
	my_logger.setLogLevel(LogLevel(log_level));
	my_logger.addAppender(appender);
};
Exemplo n.º 3
0
	std::string CFileLogger::GetFileAppenderName(log4cplus::Logger& logger)
	{
		std::string appedname = logger.getName() + "-f-";
		appedname += T2S(__LINE__);

		return appedname;
	}
Exemplo n.º 4
0
	bool CFileLogger::AddSameFileLogger(log4cplus::Logger& sublogger, log4cplus::Logger& mainlogger, int loglevel)
	{
		if ( &sublogger == &mainlogger )
		{
			return true;
		}

		SharedAppenderPtr append = mainlogger.getAppender(LOG4CPLUS_TEXT(GetFileAppenderName(mainlogger)));
		if (append)
		{
			sublogger.addAppender(append);
		}

		sublogger.setLogLevel(loglevel);

		return true;
	}
Exemplo n.º 5
0
	bool CFileLogger::AddLogger(log4cplus::Logger& logger, const std::string& logpath, int loglevel)
	{
		if (!logpath.empty())
		{
			SharedAppenderPtr append(new DailyRollingFileAppender(LOG4CPLUS_TEXT(logpath), DAILY, true, 100));
			append->setName(LOG4CPLUS_TEXT(GetFileAppenderName(logger)));

			std::auto_ptr<Layout> layout(new PatternLayout(logpattern));
			append->setLayout(layout);

			logger.addAppender(append);
		}

		logger.setLogLevel(loglevel);

		return true;
	}
Exemplo n.º 6
0
  namespace Logger {
    void init(const char*);
    extern log4cplus::Logger logger;
    
    template<typename T>
    void sprintf(std::stringstream& stream, T val) {
      stream << val;
    }

    template<typename T, typename... params>
    void sprintf(std::stringstream& stream, T val, params... args) {
      stream << val;
      sprintf(stream, args...);
    }
    
    template <typename ... params>
    void log(const char* file, int line, log4cplus::LogLevel level, params... args) {
      if (logger.isEnabledFor(level)) {
        std::stringstream stream;
        sprintf(stream, args...);
        logger.forcedLog(level, stream.str().c_str(), file, line);
      }
    }
  }
Exemplo n.º 7
0
int
main()
{
  {
    //LoggerConfig();
  }
  Log::open("/home/jan.hoelscher/devel/mec/res");
  LOGDEBUG("twest");

    logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL);
    cout << "*** calling printMessages() with TRACE set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL);
    cout << "\n*** calling printMessages() with DEBUG set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::INFO_LOG_LEVEL);
    cout << "\n*** calling printMessages() with INFO set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::WARN_LOG_LEVEL);
    cout << "\n*** calling printMessages() with WARN set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::ERROR_LOG_LEVEL);
    cout << "\n*** calling printMessages() with ERROR set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::FATAL_LOG_LEVEL);
    cout << "\n*** calling printMessages() with FATAL set: ***" << endl;
    printMessages();


  //log4cplus::Logger::shutdown();
    return 0;
}
Exemplo n.º 8
0
	void CFileLogger::SetLogger(log4cplus::Logger& logger, int loglevel)
	{
		logger.setLogLevel(loglevel);
	}
Exemplo n.º 9
0
int main( int argc, const char** argv )
{
  daemon_active = true;

  bool noDaemon = false;
  bool clockOn = false;
  std::string logFile;
  int topn;
  
  std::string configFile;
  std::string country;

  TCLAP::CmdLine cmd("OpenAlpr Daemon", ' ', Alpr::getVersion());

  TCLAP::ValueArg<std::string> countryCodeArg("c","country","Country code to identify (either us for USA or eu for Europe).  Default=us",false, "us" ,"country_code");
  TCLAP::ValueArg<std::string> configFileArg("","config","Path to the openalpr.conf file.",false, "" ,"config_file");
  TCLAP::ValueArg<int> topNArg("n","topn","Max number of possible plate numbers to return.  Default=25",false, 25 ,"topN");
  TCLAP::ValueArg<std::string> logFileArg("l","log","Log file to write to.  Default=" + DEFAULT_LOG_FILE_PATH,false, DEFAULT_LOG_FILE_PATH ,"topN");

  TCLAP::SwitchArg daemonOffSwitch("f","foreground","Set this flag for debugging.  Disables forking the process as a daemon and runs in the foreground.  Default=off", cmd, false);
  TCLAP::SwitchArg clockSwitch("","clock","Display timing information to log.  Default=off", cmd, false);

  try
  {
    
    cmd.add( countryCodeArg );
    cmd.add( topNArg );
    cmd.add( configFileArg );
    cmd.add( logFileArg );

    
    if (cmd.parse( argc, argv ) == false)
    {
      // Error occured while parsing.  Exit now.
      return 1;
    }

    country = countryCodeArg.getValue();
    configFile = configFileArg.getValue();
    logFile = logFileArg.getValue();
    topn = topNArg.getValue();
    noDaemon = daemonOffSwitch.getValue();
    clockOn = clockSwitch.getValue();
  }
  catch (TCLAP::ArgException &e)    // catch any exceptions
  {
    std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
    return 1;
  }
  
  log4cplus::BasicConfigurator config;
  config.configure();
    
  if (noDaemon == false)
  {
    // Fork off into a separate daemon
    daemon(0, 0);
    
    
    log4cplus::SharedAppenderPtr myAppender(new log4cplus::RollingFileAppender(logFile));
    myAppender->setName("alprd_appender");
    // Redirect std out to log file
    logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("alprd"));
    logger.addAppender(myAppender);
    
    
    LOG4CPLUS_INFO(logger, "Running OpenALPR daemon in daemon mode.");
  }
  else
  {
    //log4cplus::SharedAppenderPtr myAppender(new log4cplus::ConsoleAppender());
    //myAppender->setName("alprd_appender");
    // Redirect std out to log file
    logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("alprd"));
    //logger.addAppender(myAppender);
    
    LOG4CPLUS_INFO(logger, "Running OpenALPR daemon in the foreground.");
  }
  
  CSimpleIniA ini;
  ini.SetMultiKey();
  
  ini.LoadFile(DAEMON_CONFIG_FILE_PATH.c_str());
  
  std::vector<std::string> stream_urls;
  
  
  CSimpleIniA::TNamesDepend values;
  ini.GetAllValues("daemon", "stream", values);

  // sort the values into the original load order
  values.sort(CSimpleIniA::Entry::LoadOrder());

  // output all of the items
  CSimpleIniA::TNamesDepend::const_iterator i;
  for (i = values.begin(); i != values.end(); ++i) { 
      stream_urls.push_back(i->pItem);
  }
  
  
  if (stream_urls.size() == 0)
  {
    LOG4CPLUS_FATAL(logger, "No video streams defined in the configuration.");
    return 1;
  }
  
  bool storePlates = ini.GetBoolValue("daemon", "store_plates", false);
  std::string imageFolder = ini.GetValue("daemon", "store_plates_location", "/tmp/");
  bool uploadData = ini.GetBoolValue("daemon", "upload_data", false);
  std::string upload_url = ini.GetValue("daemon", "upload_address", "");
  std::string site_id = ini.GetValue("daemon", "site_id", "");
  
  LOG4CPLUS_INFO(logger, "Using: " << imageFolder << " for storing valid plate images");
  
  pid_t pid;
  
  for (int i = 0; i < stream_urls.size(); i++)
  {
    pid = fork();
    if (pid == (pid_t) 0)
    {
      // This is the child process, kick off the capture data and upload threads
      CaptureThreadData* tdata = new CaptureThreadData();
      tdata->stream_url = stream_urls[i];
      tdata->camera_id = i + 1;
      tdata->config_file = configFile;
      tdata->output_images = storePlates;
      tdata->output_image_folder = imageFolder;
      tdata->country_code = country;
      tdata->site_id = site_id;
      tdata->top_n = topn;
      tdata->clock_on = clockOn;
      
      tthread::thread* thread_recognize = new tthread::thread(streamRecognitionThread, (void*) tdata);
      
      if (uploadData)
      {
	// Kick off the data upload thread
	UploadThreadData* udata = new UploadThreadData();
	udata->upload_url = upload_url;
	tthread::thread* thread_upload = new tthread::thread(dataUploadThread, (void*) udata );
      }
      
      break;
    }

    // Parent process will continue and spawn more children
  }



  while (daemon_active)
  {
    usleep(30000);
  }

}
Exemplo n.º 10
-1
 void log(const char* file, int line, log4cplus::LogLevel level, params... args) {
   if (logger.isEnabledFor(level)) {
     std::stringstream stream;
     sprintf(stream, args...);
     logger.forcedLog(level, stream.str().c_str(), file, line);
   }
 }