double DelayedLoop(LoggerPtr logger, const String& msg) { int64_t before = System::currentTimeMillis(); int j = 0; for(int i = 0; i < runLength; i++) { logger->info(msg); if(j++ == burstLen) { j = 0; try { Thread::sleep(delay); } catch(Exception&) { } } } double actualTime = ((System::currentTimeMillis()-before)*1000.0/runLength); tcout << "actual time: " << actualTime << std::endl; return (actualTime - delay*DELAY_MULT); }
int main(int argc, char ** argv) { LoggerPtr logger = Logger::getLogger("main"); Memkeys * app = NULL; int rc = EXIT_SUCCESS; logger->setLevel(Level::INFO); // configure and initialize the app try { app = Memkeys::getInstance(argc, argv); } catch(...) { return handleConfigurationError(logger, argv[0]); } // run the app try { app->run(); } catch (const exception &ex) { logger->fatal(CONTEXT, "Error running application: %s", ex.what()); rc = EXIT_FAILURE; } logger->info(CONTEXT, "Shutting down"); // handle cleanup delete logger; delete app; delete Config::getInstance(); delete Logger::getRootLogger(); return rc; }
double NoDelayLoop(LoggerPtr logger, const String& msg) { int64_t before = System::currentTimeMillis(); for(int i = 0; i < runLength; i++) { logger->info(msg, __FILE__, __LINE__); } int64_t after = System::currentTimeMillis(); return ((after - before)*1000.0)/runLength; }
// Used for initializing app main() Memkeys * Memkeys::getInstance(int argc, char ** argv) { Config * cfg = Config::getInstance(); LoggerPtr mainLogger = Logger::getLogger("main"); try { Cli::parse(argc, argv, cfg); } catch (const exception &ex) { throw MemkeysConfigurationError(ex.what()); } mainLogger->setLevel(Level::INFO); mainLogger->info(CONTEXT, "Starting application %s. PID %d", argv[0], getpid()); Logger::getRootLogger()->setLevel(cfg->verbosity()); mainLogger->debug("Configuration\n" + cfg->toString()); return Memkeys::getInstance(cfg); }
virtual void log(const std::string& file, int line, LogLevel level, const std::string& msg) { LocationInfo loc(file.c_str(), "", line); switch(level) { case INFO : m_logger->info(msg,loc); break; case DEBUG : m_logger->debug(msg,loc); break; case WARN : m_logger->warn(msg,loc); break; case ERROR : m_logger->error(msg,loc); break; } }
// Signal handler for handling shutdowns static void signal_cb(int signum) { if (instance == NULL || instance->isShutdown()) { return; } LoggerPtr logger = Logger::getLogger("capture-engine"); // alarm means timeout has expired if (signum == SIGALRM) { logger->warning(CONTEXT, "Alarm expired, forcing shutdown"); instance->forceShutdown(); } else if (instance->isRunning()) { logger->info(CONTEXT, "Shutting down due to signal"); instance->tryShutdown(); // if we haven't shut down in 2 seconds, alarm and force it signal(SIGALRM, signal_cb); alarm(2); } else { logger->warning(CONTEXT, "Ignoring signal, already shutting down: %s", instance->getStateName().c_str()); } }
PANTHEIOS_CALL(int) pantheios_be_logEntry( void* /* feToken */ , void* /* beToken */ , int severity , char const* entry , size_t cchEntry ) { using namespace log4cxx; using namespace log4cxx::helpers; severity &= 0x07; LoggerPtr rootLogger = Logger::getRootLogger(); switch(severity) { case PANTHEIOS_SEV_EMERGENCY: case PANTHEIOS_SEV_ALERT: rootLogger->fatal(entry); break; case PANTHEIOS_SEV_CRITICAL: case PANTHEIOS_SEV_ERROR: rootLogger->error(entry); break; case PANTHEIOS_SEV_WARNING: rootLogger->warn(entry); break; case PANTHEIOS_SEV_NOTICE: case PANTHEIOS_SEV_INFORMATIONAL: rootLogger->info(entry); break; case PANTHEIOS_SEV_DEBUG: rootLogger->debug(entry); break; } return cchEntry; }
void CLog4CXX::Info(const char *loginfo) { m_logger->info(loginfo); }