Client::Client() { try { // We use ip address and process id to identify a client. char hostname[100]; gethostname(hostname, 100); m_address.name = hostname; m_address.port = getpid(); // Get configuration. string homedir = getenv("HOME"); if (!m_configured && !setFromFile("tfs_client.ini") && !setFromFile(homedir + "/.tfs_client.ini") && !setFromFile("/etc/tfs_client.ini")) { //LOG_FATAL("Client: Throw api::LoadConfigurationError") throw api::LoadConfigurationError(); } // Initialize client logger. if (m_conf.logFile[0] == '~') m_conf.logFile = homedir + m_conf.logFile.substr(1); helpers::LogLog::getLogLog()->setInternalDebugging(false); SharedAppenderPtr append_1( new RollingFileAppender(m_conf.logFile, 1024 * 1024, 1)); std::string pattern = "%D %p - %m\n"; append_1->setLayout(std::auto_ptr<Layout>(new PatternLayout(pattern))); Logger logger = Logger::getInstance("tfs_client"); logger.addAppender(append_1); // Set logger level if (m_conf.logLevel == "FATAL") logger.setLogLevel(FATAL_LOG_LEVEL); if (m_conf.logLevel == "ERROR") logger.setLogLevel(ERROR_LOG_LEVEL); if (m_conf.logLevel == "WARN") logger.setLogLevel(WARN_LOG_LEVEL); if (m_conf.logLevel == "INFO") logger.setLogLevel(INFO_LOG_LEVEL); if (m_conf.logLevel == "DEBUG") logger.setLogLevel(DEBUG_LOG_LEVEL); LOG_INFO("Client: Starts TFS Client instance."); LOG_INFO("Client: Get master address: " <<m_conf.masterIP <<":" <<m_conf.masterPort); LOG_INFO("Client: Get default buffer size: " <<m_conf.bufferSize); LOG_INFO("Client: Get log level: " <<m_conf.logLevel); LOG_INFO("Client: Get log file: " <<m_conf.logFile); // Initialize ice. Ice::CommunicatorPtr ic = Ice::initialize(); Ice::ObjectPrx base = ic->stringToProxy( "ClientService:tcp -h " + m_conf.masterIP + " -p " + m_conf.masterPort); m_service = slice::ClientServicePrx::checkedCast(base); LOG_INFO("Client: Ice service initialized.") // Begin heartbeat. IceUtil::ThreadPtr deamon = new HeartbeatDeamon(m_address, m_service); deamon->start(); LOG_INFO("Client: Heartbeat Deamon started.") } catch (Ice::Exception &ex) { LOG_FATAL("Client: Get Ice Exception:" <<ex.ice_name()); LOG_FATAL("Client: Throw api::ConnectionError"); throw api::ConnectionError(); } }
STDMETHODIMP CTongshiDVBSource::ConfigureLogging(wchar_t* logFile, wchar_t* identifier, LogLevelOption logLevel){ logger = Logger::getInstance(identifier); if(logger.getAppender(identifier)==NULL){ SharedAppenderPtr append_1( new SpecialDailyRollingFileAppender(logFile,DAILY,true,10)); std::auto_ptr<Layout> myLayout = std::auto_ptr<Layout>(new log4cplus::PatternLayout(L"%d{%d.%m.%Y %H:%M:%S,%q} %-5p [%t]: %m%n")); append_1->setName(identifier); append_1->setLayout( myLayout ); append_1->setThreshold(logLevel); logger.addAppender(append_1); } m_stream->ReconfigureLogging(identifier); return true; }
STDMETHODIMP CNetworkProvider::ConfigureLogging(wchar_t* logFile, wchar_t* identifier, LogLevelOption logLevel){ logger = Logger::getInstance(identifier); if(logger.getAppender(identifier)==NULL){ SharedAppenderPtr append_1( new SpecialDailyRollingFileAppender(logFile,DAILY,true,10)); std::auto_ptr<Layout> myLayout = std::auto_ptr<Layout>(new log4cplus::PatternLayout(L"%d{%d.%m.%Y %H:%M:%S,%q} %-5p [%t]: %m%n")); append_1->setName(identifier); append_1->setLayout( myLayout ); append_1->setThreshold(logLevel); logger.addAppender(append_1); } m_pDigitalDemodulator2Filter->ReconfigureLogging(identifier); m_pDigitalDemodulatorFilter->ReconfigureLogging(identifier); m_pDiseqCommand->ReconfigureLogging(identifier); m_pFrequencyFilter->ReconfigureLogging(identifier); m_pLnbInfoFilter->ReconfigureLogging(identifier); m_pNetworkProviderPin->ReconfigureLogging(identifier); return S_OK; }