int main(int, char **) { Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("utils.Test")); PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties")); LOG4CPLUS_ERROR(logger, "Test start"); CTimeoutManager * pInstance = CTimeoutManager::getInstance(); pInstance->addSubscriber(new CSubscriber("\n### three ###\n", 3), 500); pInstance->addSubscriber(new CSubscriber("\n### one ###\n", 1), 450); CSubscriber * pSub = new CSubscriber("\n### empty ###\n", -10); pInstance->addSubscriber(pSub, 500); pInstance->addSubscriber(new CSubscriber("\n### four ###\n", 4), 900); pInstance->removeSubscriber(pSub); pInstance->addSubscriber(new CSubscriber("\n### two ###\n", 2), 450); gSem.waitTimeout(2000); if (5 == gCount) { LOG4CPLUS_ERROR(logger, "Test passed!\n OK OK OK OK OK OK OK OK OK OK OK OK"); } else { LOG4CPLUS_ERROR(logger, "Test failed, gCount = " + convertIntegerToString(gCount)); } CTimeoutManager::deleteInstance(); CTimeoutManager::getInstance(); // check quick deleteing of CTimeoutManager instance CTimeoutManager::deleteInstance(); }
bool TestManager::RunTest(const char* path) { bool ok; TestParser testParser; Test *test = testParser.ParseTest(path); if (test != NULL) { // making log directory within tests directory: string testDirectory(path); testDirectory = testDirectory.substr(0, testDirectory.rfind(PATH_SEPARATOR) + 1); testDirectory.append(LOGS_DIRECTORY); #ifdef _WIN32 _mkdir(testDirectory.c_str()); #else mkdir(testDirectory.c_str(), S_IRWXU); #endif // setting log file name: tstring fileName(LOG4CPLUS_TEXT(path)); fileName.append(LOG4CPLUS_TEXT(".log")); size_t lastSeparatorIndex = fileName.rfind(PATH_SEPARATOR); fileName.insert(lastSeparatorIndex, 1, PATH_SEPARATOR); fileName.insert(lastSeparatorIndex + 1, LOGS_DIRECTORY); // configuring logger: PropertyConfigurator baseConfig(TESTER_LOG_CONFIG); helpers::Properties baseProperties = baseConfig.getProperties(); helpers::Properties* properties = new helpers::Properties(); vector<tstring> propertyNames = baseProperties.propertyNames(); for (vector<string>::iterator it = propertyNames.begin(); it != propertyNames.end(); it++) { tstring key("log4cplus."); key.append(it->c_str()); properties->setProperty(key, baseProperties.getProperty(it->c_str())); } properties->setProperty(LOG4CPLUS_TEXT("log4cplus.appender.RaccoonTestFileAppender.File"), fileName); Logger logger = Logger::getInstance(TESTER_LOGGER_NAME); SharedAppenderPtrList list = logger.getAllAppenders(); PropertyConfigurator config(*properties); config.configure(); for (SharedAppenderPtrList::iterator it = list.begin(); it != list.end(); it++) { logger.addAppender(*it); } LOG4CPLUS_INFO(logger, "Testing " << path << "..."); ok = RunTest(*test); delete test; delete properties; logger.removeAppender(FILE_APPENDER_NAME); } else { ok = false; } return ok; }
UINT32 Log4CPlusAdaptee::CreateLog( const char * pName , const char * pLayoutConfig , const char * pFile ) { //5 1.创建layout,这里是先定义Layout的格式. log4cplus::tstring pattern = LOG4CPLUS_TEXT(""); if (!pLayoutConfig) { pattern = LOG4CPLUS_TEXT("%d{%m/%d/%y %H:%M:%S,%Q} [%t] %-5p %c{2} %%%x%% - %X{key} - %m [%l]%n"); } //5 2.创建接纳Layout的appender.这个是用来表示是用来什么方式进行存储.可以流式.sys服务.远程服务.文件等等. #ifdef _DEBUG log4cplus::SharedAppenderPtr pAppender(new log4cplus::ConsoleAppender()); pAppender->setName(LOG4CPLUS_TEXT("log4cplus console appender")); #else log4cplus::SharedAppenderPtr pAppender(new log4cplus::FileAppender(LOG4CPLUS_TEXT("log4cplus file appender"))); #endif pAppender->setLayout(std::auto_ptr<log4cplus::Layout>(new log4cplus::PatternLayout(pattern))); //5 3.创建Categteoy策略来装Appender. log4cplus::Logger objLogger = log4cplus::Logger::getInstance(log4cplus::helpers::towstring(pName)); objLogger.setAdditivity(false); objLogger.addAppender(pAppender); objLogger.setLogLevel(log4cplus::ALL_LOG_LEVEL); return 0; }
int main(int argc, char* argv[]) { Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("test.ChannelSupervisor.Server")); PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties")); int option_index = 0; int c; while (true) { c = getopt_long(argc, argv, "x:u:r:p:", long_options, &option_index); if (-1 == c) break; switch (c) { case 'x': //Log("option x = '%s'", optarg); strncpy(cs_sock_path.begin(), optarg, cs_sock_path.size()); cs_sock_path[cs_sock_path.size() - 1] = 0; break; case 'u': //Log("option u = '%s'", optarg); strncpy(ca_sock_path.begin(), optarg, ca_sock_path.size()); ca_sock_path[ca_sock_path.size() - 1] = 0; break; default: //Log("unknown param %c (%d)", c, c); exit(1); break; } } if (ca_sock_path[0] != 0) { extern char const * gpCA_UNIX_SOCK_PATH; gpCA_UNIX_SOCK_PATH = ca_sock_path.begin(); // gpCA_UNIX_SOCK_PATH = "/tmp/axis_ca2"; } if (cs_sock_path[0] != 0) { extern char const * gpNEGOTIATOR_IPC_ADDR; gpNEGOTIATOR_IPC_ADDR = cs_sock_path.begin(); // gpNEGOTIATOR_IPC_ADDR = "/tmp/axis_neg2"; } // CServer server; server.threadFunc(); // server.start(); // while(true) // { // sleep(1000); // }; }
void InitializeLogging() { if (Logging_initialized) { return; } Logging_initialized = true; log4cplus::initialize(); log4cplus::Logger logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("logging.init")); char *prop_file = getenv("LOG4CPLUS_PROPERTIES"); if (prop_file == NULL) { // fall back to log4cplus.properties prop_file = (char *) "log4cplus.properties"; } if (access(prop_file, F_OK) == -1) { log4cplus::BasicConfigurator config; config.configure(); LOG4CPLUS_WARN(logger, "Cannot access LOG4CPLUS_PROPERTIES " << prop_file << ", using BasicConfigurator."); } else { log4cplus::PropertyConfigurator config(prop_file); config.configure(); LOG4CPLUS_INFO(logger, "LOG4CPLUS_PROPERTIES file is " << LOG4CPLUS_TEXT(prop_file)); } // Example usage of the debug logger // LOG4CPLUS_DEBUG(logger, "Pi is " << (4 * atan(1)) << " approximately"); }
int main() { log4cplus::Initializer initializer; log4cplus::BasicConfigurator config; config.configure(); log4cplus::Logger logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main")); LOG4CPLUS_WARN(logger, LOG4CPLUS_TEXT("Hello, World!")); return 0; }
int main( int argc, char **argv) { Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("ConnectivityAgent.main.test")); PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties")); CppUnit::TextUi::TestRunner runner; CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); runner.addTest( registry.makeTest() ); bool wasSucessful = runner.run( "", false ); return wasSucessful ? 0 : 1; }
void RTSPMJPEGClient::threadLoop(RTSPMJPEGClientParameters *parameters) { int clientId = parameters->clientId; RTSPMJPEGClient *instance = getInstance(); RTSPMJPEGClientStruct *pClient = instance->clients[clientId]; if (pClient == NULL) { pClient = new RTSPMJPEGClientStruct; pClient->clientId = clientId; pClient->state = RTSPMJPEGCLIENT_STATE_CLEANED; pClient->isWaiting = false; pClient->newFramesNum = 0; pClient->next = 0; for (int i = 0; i < RTSPMJPEGCLIENT_FRAME_QUEUE_LEN; i++) { pClient->frameQueue[i] = (uint8_t * ) av_malloc(RTSPMJPEGCLIENT_FRAME_BUFFER_SIZE); pClient->frameSizes[i] = 0; } instance->clients[clientId] = pClient; LOG4CPLUS_DEBUG(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_OUTPUT_LOGGER)), "[CLIENT " << pClient->clientId << "] allocated space for a new client..."); } LOG4CPLUS_TRACE(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_OUTPUT_LOGGER)), "[CLIENT " << pClient->clientId << "] threadLoop()..."); pClient->address = ((RTSPMJPEGClientParameters * ) parameters)->address; delete parameters; if (instance->_init(pClient) < 0) { instance->_clean(pClient, RTSPMJPEGCLIENT_STATE_ERROR); LOG4CPLUS_ERROR(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_ERROR_LOGGER)), "[CLIENT " << pClient->clientId << "] init failed!"); LOG4CPLUS_ERROR(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_OUTPUT_LOGGER)), "[CLIENT " << pClient->clientId << "] init failed!"); return; } pClient->state = RTSPMJPEGCLIENT_STATE_LOOPING; while (pClient->state == RTSPMJPEGCLIENT_STATE_LOOPING && instance->_readFrame(pClient) == 0) LOG4CPLUS_DEBUG(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_OUTPUT_LOGGER)), "[CLIENT " << pClient->clientId << "] while()..."); // set CLEANED only if it was correctly stopped. ERROR otherwise. Don't set // any state greater then CLEANED because they're all states indicating an // action being taken instance->_clean(pClient, pClient->state == RTSPMJPEGCLIENT_STATE_STOPPING ? RTSPMJPEGCLIENT_STATE_CLEANED : RTSPMJPEGCLIENT_STATE_ERROR); }
void RTSPMJPEGClient::_logAVError(RTSPMJPEGClientStruct *pClient, int error) { if (av_strerror(error, pClient->errbuf, RTSPMJPEGCLIENT_ERRBUF_SIZE) == 0) { LOG4CPLUS_ERROR(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_ERROR_LOGGER)), "[CLIENT " << pClient->clientId << "] LibAV error: " << pClient->errbuf); LOG4CPLUS_ERROR(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_OUTPUT_LOGGER)), "[CLIENT " << pClient->clientId << "] LibAV error: " << pClient->errbuf); } else { LOG4CPLUS_ERROR(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_ERROR_LOGGER)), "[CLIENT " << pClient->clientId << "] LibAV error: Unknown error..."); LOG4CPLUS_ERROR(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_OUTPUT_LOGGER)), "[CLIENT " << pClient->clientId << "] LibAV error: Unknown error..."); } }
int main(int argc, char* argv[]) { Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("ConnectivityAgent.test.client.main")); PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties")); int option_index = 0; int c; while (true) { c = getopt_long(argc, argv, "x:u:r:p:", long_options, &option_index); if (-1 == c) break; switch (c) { case 'u': //Log("option u = '%s'", optarg); strncpy(ca_sock_path.begin(), optarg, ca_sock_path.size()); ca_sock_path[ca_sock_path.size() - 1] = 0; break; default: //Log("unknown param %c (%d)", c, c); exit(1); break; } } if (ca_sock_path[0] != 0) { extern char const * gpCA_UNIX_SOCK_PATH; gpCA_UNIX_SOCK_PATH = ca_sock_path.begin(); } // please run client first CSignalSemaphoreInterproc::unlink("/connectivity_agent_test_server"); CSignalSemaphoreInterproc::unlink("/connectivity_agent_test_client"); CClient client; client.threadFunc(); // client.start(); // while(true) // { // sleep(1000); // }; }
int main() { Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("samples.Applications.EchoServer")); PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("echoServerLog.properties")); LOG4CPLUS_INFO(logger, " begin Echo Client main()"); EchoServer * server = new EchoServer(); server->run(); delete server; LOG4CPLUS_INFO(logger, "end Echo Client main()"); return 0; }
InternalCoreUnloadInstances::InternalCoreUnloadInstances(IPmpPimToCore * core, BaseUid id) : mCore(core) , mId(id) , mLogger(Logger::getInstance(LOG4CPLUS_TEXT("profileManager.PMP.Events"))) { assert(mCore); }
bool NuiSLAMPointCloud::estimateNormals(NuiKinfuXYZRGB* pXYZRGB, float filterLeafSize) { if (!pXYZRGB) return false; if (filterLeafSize <= 0.0f) return false; LOG4CPLUS_INFO(NuiLogger::instance().consoleLogger(), LOG4CPLUS_TEXT("Estimating normals...")); pcl::VoxelGrid<pcl::PointXYZRGB> sor; sor.setInputCloud(pXYZRGB->getPtr()); sor.setLeafSize(filterLeafSize, filterLeafSize, filterLeafSize); pcl::PointCloud<pcl::PointXYZRGB> tempCloud; sor.filter(tempCloud); pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> n; pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>); pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZRGB>); tree->setInputCloud(tempCloud.makeShared()); n.setInputCloud(tempCloud.makeShared()); n.setSearchMethod(tree); n.setKSearch(20); n.compute(*normals); pcl::concatenateFields(tempCloud, *normals, m_pointCloud); return true; }
bool LobbyServer::InitLog4cpp() { PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("./lobby.properties")); Logger root = Logger::getRoot(); return true; }
MockTransportManagerClient(ITransportManager & TransportManager) : mTransportManager(TransportManager) , mDeviceList() , mLogger(log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("TransportManagerTest"))) { }
namespace NsConnectionHandler { log4cplus::Logger CDevice::mLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("ConnectionHandler")); CDevice::CDevice(tDeviceHandle aDeviceHandle, std::string aUserFriendlyName): mDeviceHandle(aDeviceHandle), mUserFriendlyName(aUserFriendlyName) { } CDevice::~CDevice() { } tDeviceHandle CDevice::getDeviceHandle() const { return mDeviceHandle; } std::string CDevice::getUserFriendlyName() const { return mUserFriendlyName; } }/* namespace NsConnectionHandler */
Waiter::Waiter(WaiterMode mode) : mWaiterMode(mode) { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__); PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties")); }
SystemControllerMsg::SystemControllerMsg() : SystemControllerMsgProxy("SysCtrl_PrflMngr") , mEventFactory(NULL) , mLogger(Logger::getInstance(LOG4CPLUS_TEXT("profileManager.PMP.SystemControllerMsg"))) { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__ ); bool noError = false; for (int i = 0; i < 5; ++i) { LOG4CPLUS_INFO(mLogger, "Try to connect to System Controller number " + convertIntegerToString(i)); if (connect().isNoError()) { noError = true; break; } usleep(250000); } if (!noError) { LOG4CPLUS_FATAL(mLogger, "Can't connect to system controller"); killProcess(1); } }
CPlayer::CPlayer() : mVideoWidget(0), mMediaPlayer(NULL), mPlaybackStartedCallback(NULL) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties")); mMutex = new CRWMutex(); const char * const argv[] = { "--no-video-title-show", "-vvv", "--packetizer-mpegvideo-sync-iframe" }; mInst = libvlc_new(sizeof(argv) / sizeof(*argv), argv); assert(mInst); mVolume = VOLUME_INIT; hasPlayerInstance = false; //for process show and hide in qt-threads if (connect(this, SIGNAL(playerPlaySig(QString, QString)), this, SLOT(playerPlaySlot(QString, QString)), Qt::QueuedConnection) == false) { LOG4CPLUS_INFO(msLogger, "qt - connect play failed!"); killProcess(1); } if (connect(this, SIGNAL(playerStopSig()), this, SLOT(playerStopSlot()), Qt::QueuedConnection) == false) { LOG4CPLUS_INFO(msLogger, "qt - connect stop failed!"); killProcess(1); } }
void RTSPMJPEGClient::_clean(RTSPMJPEGClientStruct *pClient, int stateToSet) { // close the codecs if (pClient->_pCodecCtx != NULL) { avcodec_close(pClient->_pCodecCtx); pClient->_pCodecCtx = NULL; } if (pClient->_pCodecCtxOrig != NULL) { avcodec_close(pClient->_pCodecCtxOrig); pClient->_pCodecCtxOrig = NULL; } // close the video input if (pClient->_pFormatCtx != NULL) { avformat_close_input(&pClient->_pFormatCtx); pClient->_pFormatCtx = NULL; } pClient->state = stateToSet; pClient->isWaiting = false; pClient->newFramesNum = 0; LOG4CPLUS_TRACE(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_OUTPUT_LOGGER)), "[CLIENT " << pClient->clientId << "] STATE = " << state_to_string(pClient->state)); }
PmpSessionProtocol::PmpSessionProtocol() : mLogger(Logger::getInstance(LOG4CPLUS_TEXT("profileManager.PMP.interaction.PmpSessionProtocol"))) , mPmpProtocol(NULL) , mEventFactory(NULL) { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__ ); }
InternalCoreUnlockAuthenticationProfile::InternalCoreUnlockAuthenticationProfile(PmpCore * core, CSignalSemaphore * sem) : mCore(core) , mSem(sem) , mLogger(Logger::getInstance(LOG4CPLUS_TEXT("profileManager.PMP.Events"))) { }
CoreProtocolGetAvailableProfileComplementsResponse:: CoreProtocolGetAvailableProfileComplementsResponse(PmpCore * core, const std::list<Profile::Uid> & complements) : mCore(core) , mComplements(complements) , mLogger(Logger::getInstance(LOG4CPLUS_TEXT("profileManager.PMP.Events"))) { }
void InitLogger(bool daemonized) { initialize(); if (daemonized) PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("configLog.txt")); /* else PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("configLog.txt"));*/ }
ServiceRepository::ServiceRepository(conf::Configurator * configurator) : mLogger(Logger::getInstance(LOG4CPLUS_TEXT("profileManager.Repository"))) , mConfigurator(configurator) { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__ ); init(); printRepository(); }
GTEST_API_ int main(int argc, char **argv) { InitializeLogging(); log4cplus::Logger logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main")); LOG4CPLUS_INFO(logger, "Running main()"); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
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; }
PimProtocolProfileDied::PimProtocolProfileDied(PmpPim * pim, const Profile::IUid & piuid, const Service::Uid & sid) : mPim(pim) , mPIUid(piuid) , mSUid(sid) , mLogger(Logger::getInstance(LOG4CPLUS_TEXT("profileManager.PMP.Events"))) { }
namespace Ipc { Logger CPmpController::msLogger = Logger::getInstance(LOG4CPLUS_TEXT("AppMan.Ipc.AmpForPmp.Controller")); CPmpController::CPmpController() : mpServer(new CAppManPmpIpcServer()) , mpConnection(new CPmpConnection(mpServer)) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); assert(mpServer); assert(mpConnection); mpConnection->connect(); usleep(125000); } CPmpController::~CPmpController() { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); mpServer->init(0,0); mpConnection->disconnect(); delete mpConnection; delete mpServer; } CPmpController * CPmpController::instance() { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); static CPmpController sInstance; return &sInstance; } IPmpHandler * CPmpController::pmpHandler() { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); return mpServer; } void CPmpController::init(IPmpRequest * pRequest, IPmpConnectionStatus * pConnectionStatus) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); mpServer->init(pRequest,pConnectionStatus); } void CPmpController::uninit() { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); init(0,0); } bool CPmpController::checkConnection() const { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); return mpServer->checkConnection(); } }
void RTSPMJPEGClient::abort(int clientId) { if (clients[clientId]->state <= RTSPMJPEGCLIENT_STATE_CLEANED) return; clients[clientId]->state = RTSPMJPEGCLIENT_STATE_ABORTING; LOG4CPLUS_TRACE(Logger::getInstance(LOG4CPLUS_TEXT(DEFAULT_OUTPUT_LOGGER)), "[CLIENT " << clientId << "] STATE = " << state_to_string(clients[clientId]->state)); }