Ejemplo n.º 1
0
 /**
 Intialize root logger.
 
 @param pattern Log pattern.
 @param immediateFlush When it is set true, output stream will be flushed 
                       after each appended event.
 @return Logger instance.
 */
 static Logger InitLogger(tstring pattern = tstring(LOG_PATTERN), 
                          bool immediateFlush = LOG_DEFAULT_IMMEDIATE_FLUSH)
 {
  log4cplus::initialize();

  log4cplus::SharedAppenderPtr appender(
   new log4cplus::ConsoleAppender(false, immediateFlush));
  appender->setName(TEXT("default"));
  appender->setLayout(std::auto_ptr<log4cplus::Layout>(
   new log4cplus::PatternLayout(pattern)));

  Logger logger = log4cplus::Logger::getRoot();
  logger.addAppender(appender);

#if defined(WIN32) // && defined(_DEBUG) 

  log4cplus::SharedAppenderPtr _appender(new log4cplus::Win32DebugAppender);
  _appender->setName(TEXT("win32"));
  _appender->setLayout(std::auto_ptr<log4cplus::PatternLayout>(
   new log4cplus::PatternLayout(pattern)));
  logger.addAppender(_appender);
    
#endif
  
#ifdef _DEBUG
  logger.setLogLevel(LEVEL_DEBUG);
#else
  logger.setLogLevel(LEVEL_INFO);
#endif

  return logger;
 }
Ejemplo n.º 2
0
bool AddAppender(Logger log,const LogConfigure& config){
    if(!log.getAllAppenders().empty()){
        log.removeAllAppenders();
    }
    if(config.console){
        SharedAppenderPtr append(new ConsoleAppender());
        log.addAppender(append);
    }

    if(!config.file_path.empty()){
        SharedAppenderPtr append(new RollingFileAppender(config.file_path));
        log.addAppender(append);
    }
    //layout ,we doesn't support custom layout
    //PatternLayout Detailed Description http://log4cplus.sourceforge.net/docs/html/classlog4cplus_1_1PatternLayout.html
    for(log4cplus::SharedAppenderPtr appender:log.getAllAppenders()){
        log4cplus::tstring pattern = LOG4CPLUS_TEXT("%d{%y/%m/%d %H:%M:%S,%Q} [%t][%i] %-5p %m [%c:%L]%n");
        appender->setLayout( std::auto_ptr<Layout>(new PatternLayout(pattern)) );
    }

    if(log.getAllAppenders().empty()){
        return false;
    }
    return true;
}
Ejemplo n.º 3
0
void object::test<11>()
{
    string stmpfile(TOP_BUILD_DIR);
    stmpfile += "/lt.test11.log";
    const char *filename = stmpfile.c_str();
    unlink(filename);
    Logger *logger = alog::Logger::getLogger("abc");
    PatternLayout *layout = new PatternLayout();
    PatternLayout *layout2 = new PatternLayout();
    layout->setLogPattern("[%%d] [%%F -- LINE(%%n) -- %%f()] [%%m]");
    layout2->setLogPattern("[%%d] [%%F -- LINE(%%n) -- %%f()] [%%m]");
    alog::Appender *appender1 = alog::FileAppender::getAppender(filename);
    appender1->setLayout(layout);
    alog::Appender *appender2 = alog::ConsoleAppender::getAppender();
    cout << " ### appender: " << appender2 << endl;
    appender2->setLayout(layout2);
    logger->setAppender(appender1);
    logger->addAppender(appender2);

    char buffer[Logger::MAX_MESSAGE_LENGTH + 100];                                                                                        
    int buffLen =  sizeof(buffer);
    memset(buffer, 'a', buffLen);
    buffer[buffLen -1] = '\0';
    logger->log(LOG_LEVEL_ERROR, "%s", buffer);
    logger->flush();

    int lineCount = getFileLineCount(filename);
    ensure("test 11 lineCount is right", lineCount == 1);
    unlink(filename);
    Logger::shutdown();
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {

    // initilize log log4cplus
    SharedObjectPtr<Appender> append(new FileAppender("submitter.log"));
    append->setName(LOG4CPLUS_TEXT("append for submitter"));
    auto_ptr<Layout> layout(new PatternLayout(LOG4CPLUS_TEXT("%d{%y/%m/%d %H:%M:%S} %p [%l]: %m %n")));
    append->setLayout(layout);
    Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("submitter"));
    logger.addAppender(append);
    logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL);
    LOG4CPLUS_DEBUG(logger, "This is the FIRST debug message");
    LOG4CPLUS_INFO(logger, "This is the FIRST info message");
    LOG4CPLUS_ERROR(logger, "This is the FIRST error message");

    string app_file_name = "a.txt";
    string app_file_source = "/user/root/test";
    string app_file_locate = "/home/yesw/";

    if(false == AppFilePtrI::Instance()->CreateAppFile(app_file_name, app_file_locate, app_file_source)){
        //LOG4CPLUS_ERROR(logger, "cmd parse error, unknown run mode");
	cout<< "create app file to hdfs error"<< endl;
	return -1;
    }
    return 0; 
}  
Ejemplo n.º 5
0
LoadDialog::LoadDialog(QWidget *parent) :
		QDialog(parent),
	ui(new Ui::LoadDialog) {
	ui->setupUi(this);
	ui->progressBar->setTextVisible(false);
	// weird, Qt/Win needs this to get a busy indicator
	ui->progressBar->setValue(1);
	ui->progressBar->setRange(0, 0);
	ui->console->hide();
	resize(400,180);
	m_consoleAppender = new QConsoleAppender();
	Logger *logger = Thread::getThread()->getLogger();
	m_oldLogLevel = logger->getLogLevel();
	//logger->setLogLevel(EDebug);
	logger->addAppender(m_consoleAppender);
	connect(m_consoleAppender, SIGNAL(textMessage(ELogLevel, const QString &)),
		this, SLOT(onTextMessage(ELogLevel, const QString &)), Qt::QueuedConnection);
	QFont font("Monospace");
	font.setStyleHint(QFont::TypeWriter);
#if defined(__OSX__)
	font.setPointSize(10);
	QFont headingFont = ui->heading->font();
	headingFont.setPointSize(14);
	ui->heading->setFont(headingFont);
#else
	font.setPointSize(8);
#endif
	ui->console->setFont(font);
	ui->console->setReadOnly(true);
	QPalette palette;
	palette.setColor(QPalette::Base, Qt::black);
	ui->console->setPalette(palette);
}
Ejemplo n.º 6
0
	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;
	}
Ejemplo n.º 7
0
 /**
 Configurate specified logger.
 
 @param name Logger name.
 @param logLevel Log level.
 @param logFile Log file name, empty if console.
 @param immediateFlush When it is set true, output stream will be flushed
                       after each appended event.
 @return Has the logger been configurated before?
 */
 static bool ConfigLogger(const tstring& name = TEXT(""), 
                          const tstring& logLevel = TEXT("INFO"), 
                          const tstring& logFile = TEXT(""),
                          bool immediateFlush = LOG_DEFAULT_IMMEDIATE_FLUSH)
 {
  Logger logger = GetLogger(name);
  bool existed = false;
    
  if(name.empty()) // Root.
  {
   if(logger.getAppender(TEXT("default")))
    existed = true;   
  }
  
  if(logger.getAppender(TEXT("config")))
   existed = true;

  if(logger.getAppender(TEXT("default")))
   logger.removeAppender(TEXT("default"));
   
  if(logger.getAppender(TEXT("config")))
   logger.removeAppender(TEXT("config"));

  if(!logFile.empty())
  {    
   log4cplus::SharedAppenderPtr appender(new log4cplus::FileAppender(
    logFile, std::ios::app, immediateFlush));
   appender->setName(TEXT("config"));
   appender->setLayout(std::auto_ptr<log4cplus::Layout>(
    new log4cplus::PatternLayout(LOG_PATTERN)));   
   logger.addAppender(appender);
  }
  else
  {
   log4cplus::SharedAppenderPtr appender(
    new log4cplus::ConsoleAppender(false, immediateFlush));
   appender->setName(TEXT("config"));
   appender->setLayout(std::auto_ptr<log4cplus::Layout>(
    new log4cplus::PatternLayout(LOG_PATTERN)));
   logger.addAppender(appender);
  }

  log4cplus::LogLevelManager& llm = log4cplus::getLogLevelManager();
  logger.setLogLevel(llm.fromString(logLevel));
  
  return existed;
 }
Ejemplo n.º 8
0
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();
    }
}
Ejemplo n.º 9
0
void Logger::staticInitialization() {
	Logger *logger = new Logger(EInfo);
	ref<Appender> appender = new StreamAppender(&std::cout);
	ref<Formatter> formatter = new DefaultFormatter();
	logger->addAppender(appender);
	logger->setFormatter(formatter);
	Thread::getThread()->setLogger(logger);
}
Ejemplo n.º 10
0
int32_t main(int32_t argc, char ** argv) {
    int32_t result;
    bool debug = false;
    while((result = getopt(argc, argv, "d")) != -1) {
        switch(result) {
        case 'd':
            debug = true;
            break;
        default:
            fprintf(stderr, "unknown option: %c\n", (char)optopt);
            break;
        }
    }
    SharedObjectPtr<Appender> append(new ConsoleAppender());
    append->setName(LOG4CPLUS_TEXT("append for master"));
    auto_ptr<Layout> layout(new PatternLayout(LOG4CPLUS_TEXT("%d{%m/%d/%y %H:%M:%S} %p %l:%m %n")));
    append->setLayout(layout);
    Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("master"));
    logger.addAppender(append);

    if(debug) {
        logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL);
    } else {
        logger.setLogLevel(log4cplus::INFO_LOG_LEVEL);
    }

    char *p = getenv("LYNN_HOME");
    if( NULL == p) {
        LOG4CPLUS_ERROR(logger, "LYNN_HOME is not set");
        exit(1);
    }

    string lynn_home(p);
    string conf_file = lynn_home + "/conf/master.xml";
    if(MasterConfigI::Instance()->Init(conf_file) != 0) {
        LOG4CPLUS_ERROR(logger, "error in reading master config");
        exit(1);
    }
   
    if(IpPoolI::Instance()->Init() != 0) {
        LOG4CPLUS_ERROR(logger, "error in init ip pool");
        exit(1);
    }

    thread task_processor_t(TaskProcessor);
    thread scheduler_processor_t(SchedulerProcessor);
    thread state_event_processor_t(StateEventProcessor);
   
    //启动Watcher线程
    WatcherI::Instance()->Start(); 
   
    Rpc<MasterService, MasterProcessor>::Listen(atoi(MasterConfigI::Instance()->Get("port").c_str()));
    return 0;
}
Ejemplo n.º 11
0
void setupLogToDebugger( const Level& level,
                         const TimeFormat& timeFormat,
                         const std::string& sLayout,
                         Logger& logger )
{
    LayoutPtr layout( layoutFromString( sLayout ) );
    layout->setTimeFormat( timeFormat );

    DebuggerAppenderPtr apdr( new DebuggerAppender( layout ) );
    apdr->setThreshold( level );
    logger.addAppender( apdr ); 
}
Ejemplo n.º 12
0
void setupLogToConsole( const Level& level,
                        const std::string& sConsoleTitle,
                        const TimeFormat& timeFormat,
                        const std::string& sLayout,
                        Logger& logger )
{
    LayoutPtr layout( layoutFromString( sLayout ) );
    layout->setTimeFormat( timeFormat );

    ConsoleAppenderPtr apdr( new ConsoleAppender( layout, sConsoleTitle ) );
    apdr->setThreshold( level );
    logger.addAppender( apdr ); 
}
Ejemplo n.º 13
0
int main(int argc, char **argv) 
{ 
    // 定义一个控制台的Appender 
    SharedAppenderPtr pConsoleAppender(new ConsoleAppender()); 

    // 定义Logger 
    Logger pTestLogger = Logger::getInstance("LoggerName");    

    // 将需要关联Logger的Appender添加到Logger上 
    pTestLogger.addAppender(pConsoleAppender); 

    // 输出日志信息 
    LOG4CPLUS_WARN(pTestLogger, "This is a <Warn> log message..."); 
    
    return 0; 
}
Ejemplo n.º 14
0
void setupLogToFile( const boost::filesystem::path& logFilePath,
                     const Level& level,
                     const FileMode& fileMode,
                     const TimeFormat& timeFormat,
                     const std::string& sLayout,
                     unsigned int nRolloverSizeKB,
                     Logger& logger )
{
    LayoutPtr layout( layoutFromString( sLayout ) );
    layout->setTimeFormat( timeFormat );

    FileAppenderPtr apdr( new FileAppender( logFilePath, layout,
                                            fileMode, nRolloverSizeKB ) );
    apdr->setThreshold( level );
    logger.addAppender( apdr ); 
}
Ejemplo n.º 15
0
void object::test<6>()
{ 
    string stmpfile(TOP_BUILD_DIR);
    stmpfile += "/lt.test6.log";   
    const char *filename = stmpfile.c_str();
    unlink(filename);
    Logger *logger = alog::Logger::getLogger("isearch");
    logger->setAppender(alog::FileAppender::getAppender(filename));
    logger->addAppender(alog::ConsoleAppender::getAppender());

    char buffer[Logger::MAX_MESSAGE_LENGTH + 20];
    int buffLen =  sizeof(buffer);
    memset(buffer, 'x', buffLen);
    buffer[buffLen -1] = '\0';
    logger->log(LOG_LEVEL_ERROR, "%s", buffer);
    logger->flush();

    int lineCount = getFileLineCount(filename);
    ensure("test 6 lineCount is right", lineCount == 1);
    unlink(filename);
    Logger::shutdown();
}
Ejemplo n.º 16
0
 void AddConsoleAppender(Logger& logger)
 {
     log4cplus::SharedAppenderPtr appender(new log4cplus::ConsoleAppender());            
     logger.addAppender(appender);
 }
Ejemplo n.º 17
0
 void AddFileAppender(Logger& logger, const string& path)
 {
     log4cplus::SharedAppenderPtr appender(new log4cplus::FileAppender(path));
     logger.addAppender(appender);
 }
Ejemplo n.º 18
0
void object::test<1>()
{
    Logger *logger = Logger::getRootLogger();
    ensure("## root logger is legal", logger != NULL);
    ensure("## root logger's name is right", logger->getName() == "");
    ensure("## root logger's inherit flag is right", logger->getInheritFlag() == true);

    string stmpfile(TOP_BUILD_DIR);
    stmpfile += "/lt.case1.log"; 
    string stmpfile2(TOP_BUILD_DIR);
    stmpfile2 += "/lt.case1.log2";

    const char* tmpfile = stmpfile.c_str();
    const char* tmpfile2 = stmpfile2.c_str();

    unlink(tmpfile);
    unlink(tmpfile2);

    logger->setAppender(FileAppender::getAppender(tmpfile));
    logger->addAppender(FileAppender::getAppender(tmpfile2));
    logger->setLevel(LOG_LEVEL_ERROR);
    ensure("## level set is right", logger->getLevel() == LOG_LEVEL_ERROR);

    int count = 0;
    while (count < 10000)
    {
        logger->log(LOG_LEVEL_DEBUG, "debug message:%d", count);
        logger->log(LOG_LEVEL_INFO, "info message:%d", count);
        logger->log(LOG_LEVEL_ERROR, __FILE__, __LINE__, __FUNCTION__, "error message:%d", count);
        logger->log(LOG_LEVEL_FATAL, __FILE__, __LINE__, __FUNCTION__, "fatal message:%d", count);
        count++;
    }

    int lineCount = getFileLineCount(tmpfile);
   // cout << "lineCount: " << lineCount;
    ensure("## message count is right", lineCount == 20000);
    lineCount = getFileLineCount(tmpfile2);
   // cout << "lineCount: " << lineCount;
    ensure("## message count is right 2", lineCount == 20000);

    logger->setLevel(LOG_LEVEL_DEBUG);
    while (count < 30000)
    {
        logger->log(LOG_LEVEL_DEBUG, "debug message:%d", count);
        logger->log(LOG_LEVEL_INFO, "info message:%d", count);
        logger->log(LOG_LEVEL_ERROR, __FILE__, __LINE__, __FUNCTION__, "error message:%d", count);
        logger->log(LOG_LEVEL_FATAL, __FILE__, __LINE__, __FUNCTION__, "fatal message:%d", count);
        count++;
    }

    lineCount = getFileLineCount(tmpfile);
    //cout << "lineCount: " << lineCount;
    ensure("## message count is right", lineCount == 100000);
    lineCount = getFileLineCount(tmpfile2);
    //cout << "lineCount: " << lineCount;
    ensure("## message count is right 2", lineCount == 100000);

    unlink(tmpfile);
    unlink(tmpfile2);
    Logger::shutdown();
}
Ejemplo n.º 19
0
void object::test<3>()
{ 
    string stmpfile1(TOP_BUILD_DIR);
    stmpfile1 += "/LoggerTest1-1.log";   
    string stmpfile2(TOP_BUILD_DIR);
    stmpfile2 += "/LoggerTest1-2.log";  
    const char *tmpfile1 = stmpfile1.c_str();
    const char *tmpfile2 = stmpfile2.c_str();
    unlink(tmpfile1);
    unlink(tmpfile2);
    Logger* logger = Logger::getLogger("simpleLogger");
    uint32_t level = logger->getLevel();
    uint32_t rootLevel = Logger::getRootLogger()->getLevel();
    ensure("## Default log level is INFO", level == LOG_LEVEL_INFO);
    ensure("## Default root log level is INFO", rootLevel == LOG_LEVEL_INFO);

    bool inherit = logger->getInheritFlag();
    ensure("## Default inherit is true", inherit == true);

    std::string name = logger->getName();
    ensure("## Logger is correctly named", name == "simpleLogger");

    bool isEnable = logger->isLevelEnabled(LOG_LEVEL_ERROR);
    ensure("## ERROR is able to log on INFO", isEnable== true);

    isEnable = logger->isLevelEnabled(LOG_LEVEL_DEBUG);
    ensure("## DEBUG is unable to log on INFO", isEnable== false);

    logger->setLevel(LOG_LEVEL_ERROR);
    level = logger->getLevel();
    ensure("## Set log level is correct", level == LOG_LEVEL_ERROR);

    Appender *appender = FileAppender::getAppender(tmpfile1);
    logger->setAppender(appender);
    logger->log(LOG_LEVEL_ERROR, "simpletest");
    logger->log(LOG_LEVEL_FATAL, "simpletest %s", "...");
    logger->logPureMessage(LOG_LEVEL_ERROR, "simpletest pure msg");
    logger->log(LOG_LEVEL_INFO, "should not be output");

    int lineCount = getFileLineCount(tmpfile1);
    ensure("## setAppender : lineCount is equal to logCount", lineCount == 3);

    Appender *appender2 = FileAppender::getAppender(tmpfile2);
    logger->addAppender(appender2);
    logger->log(LOG_LEVEL_ERROR, "simpletest");
    logger->log(LOG_LEVEL_FATAL, "filename", 10, "function", "simpletest %s", "...");
    logger->logPureMessage(LOG_LEVEL_ERROR, "simpletest pure msg");
    logger->log(LOG_LEVEL_INFO, "should not be output");
    std::ifstream logfile2(tmpfile2);

    int lineCount2 = getFileLineCount(tmpfile2);
    ensure("## addAppender : lineCount is equal to logCount", lineCount2 == 3);

    logger->removeAllAppenders();
    logger->log(LOG_LEVEL_ERROR, "not be output");

    int lineCount3 = getFileLineCount(tmpfile1);
    ensure("## removeAllAppenders1 : lineCount is equal to logCount", lineCount3 == 6);

    int lineCount4 = getFileLineCount(tmpfile2);
    ensure("## removeAllAppenders2 : lineCount is equal to logCount", lineCount4 == 3); 
 
    unlink(tmpfile1);
    unlink(tmpfile2);

    Logger::shutdown();
}
Ejemplo n.º 20
0
int main (int argc, char *argv[]) {
    SharedAppenderPtr myAppender(new ConsoleAppender());
    myAppender->setName("myAppenderName");

    std::auto_ptr<Layout> myLayout = std::auto_ptr<Layout>(new log4cplus::TTCCLayout());
    myAppender->setLayout(myLayout);

    myLogger.addAppender(myAppender);
    myLogger.setLogLevel(DEBUG_LOG_LEVEL);

    SkyDragonEngineLogger::Instance()->AddAppender(myAppender);
    SkyDragonEngineLogger::Instance()->SetLogLevel(DEBUG_LOG_LEVEL);
	LOG4CPLUS_DEBUG(myLogger, "Testing adfsfsdfs  zzzzz");

    LightSource l;
    l.Position[0] = 0.f;
    l.Position[1] =  6.f;
    l.Position[2] =  10.f;
    l.Position[3] =  1.f;
    l.Ambient[0] = .2f;
    l.Ambient[1] =  .2f;
    l.Ambient[2] =  .2f;
    l.Ambient[3] =  1.f;
    l.Diffuse[0] = 1.f;
    l.Diffuse[1] =  1.f;
    l.Diffuse[2] =  1.f;
    l.Diffuse[3] =  1.f;
    l.Specular[0] = 1.f;
    l.Specular[1] =  1.f;
    l.Specular[2] =  1.f;
    l.Specular[3] =  1.f;
    
    ISceneObject* cube = CreateCubeObject();
    
    scene.AddLight(l);
    scene.SetRenderer(new GLSceneRenderer());
    scene.AddSceneObject(cube);
    
    ISceneObject* marble = CreatePlayerObject();
    scene.AddSceneObject(marble);
    
    ICollisionManager* collisionManager = new CollisionManager();
    collisionManager->AddCollisionHandler ( &HandleCollision );
    scene.SetCollisionManager ( collisionManager );
    
    //camera = new GLSatelliteCamera ( Vector3d ( 0.f, 0.f, 3.f ), marble );
    camera = new GLSphericalCamera();
    scene.SetCamera ( camera );
    
    ISceneObject* wall1 = CreateWallObject("Left wall", Vector3d (-2.5f, -0.1f, 0.f));
    scene.AddSceneObject(wall1);
    
    ISceneObject* wall2 = CreateWallObject("Right wall", Vector3d (2.5f, -0.1f, 0.f));
    scene.AddSceneObject(wall2);
    
    glutInit ( &argc, argv );
    glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutInitWindowSize ( WINDOW_WIDTH, WINDOW_HEIGHT );
    glutInitWindowPosition ( 100, 100 );
    glutCreateWindow ( argv[0] );
    
    glutDisplayFunc(draw_contents);
    glutReshapeFunc(resize_handler);
    glutIdleFunc(update_animation);
    glutMouseFunc(mouse_handler);
    glutMotionFunc(motion_handler);
    
    glutKeyboardFunc(kb_handler);
    glutSpecialFunc(kb_special_handler);
    
    glutMainLoop();
    
    return EXIT_SUCCESS;
}
Ejemplo n.º 21
0
int _tmain(int argc, _TCHAR* argv[])
{
	using namespace Framework;
	using namespace log4cplus;
	using namespace std;
	using namespace TcpSocketServerSide;
	using namespace Business;
	using namespace Business::Handlers;
	
	
	// configure log4cplus
	SharedAppenderPtr appender(new DailyRollingFileAppender(_T("Whisper.log")));
	//tstring patternExp = _T("%-5p - %Y-%m-%d %H:%M:%S - %l - %m%n");
	tstring patternExp = _T("%-5p - %D - %l - %m%n");
	auto_ptr<Layout> layout(new PatternLayout(patternExp));
	appender->setLayout(layout);
	Logger logger = Logger::getRoot();
	logger.addAppender(appender);

	// configure Framework
	Configurations::BufferSize = 1024;
	Configurations::Logger = &logger;

	try{

		ITaskFactory* taskFactory = new DefaultTaskFactory(1);

		SocketServer* server = new TcpSocketServer(
			"127.0.0.1", //"192.168.1.103",//
			8888,
			taskFactory
			);

		auto dispatcher = new TcpSocketEventDispatcher(*server);
		auto socketFactory = new TcpSocketFactory();
		auto manager = new TcpConnectionManager(*server, *dispatcher, *socketFactory);
		auto handler = new WhisperSocketEventHandler(*server);
		auto serverEventHandler = 
			new WhisperSocketEventHandler::ServerEventHandler(
			*server,
			*handler
			);

		/* register message handler */
		PacketDispatcher& packetDispatcher = handler->GetPacketDispatcher();
		packetDispatcher.Register(new AuthenticateRequestHandler());


		/* register message handler */

		server->SetSocketEventDispatcher(dispatcher);
		server->SetConnectionManager(manager);
		server->SetSocketEventHandler(handler);
		server->SetServerEventHandler(serverEventHandler);

		server->Start();

		/*Sleep(10*1000);*/
		//server->Shutdown();

		server->WaitForShutdown();
		delete server;
		cout << " Server closed." << endl;
	}
	catch(std::exception &ex){
		cout << ex.what() << endl;
	}

	cin.get();

	return 0;
}