예제 #1
0
void GamePlay::updatehightestRecord() {
	float beforescore = UserDefault::sharedUserDefault()->getFloatForKey(
			getLevelString(GamePlay::instance()->getLevel()), 7200.0);
	if (beforescore > timeplay) {
		UserDefault::sharedUserDefault()->setFloatForKey(
				getLevelString(GamePlay::instance()->getLevel()), timeplay);
		UserDefault::sharedUserDefault()->flush();
		this->highScore = timeplay;
	} else {
		this->highScore = beforescore;
	}
}
예제 #2
0
void Log::log(WarningLevel level, const string& str)
{
  if (level >= _level)
  {
    QDateTime dt = QDateTime::currentDateTime();

    // takes the form: "09:34:21.635 WARN  <str>"
    cout << dt.toString("hh:mm:ss.zzz") << " " << getLevelString(level) << "  " << str << endl;
  }
}
예제 #3
0
void Log::log(WarningLevel level, const string& str, const string& filename,
  const string& /*functionName*/, int lineNumber)
{
  if (level >= _level)
  {
    QDateTime dt = QDateTime::currentDateTime();

    // takes the form: "09:34:21.635 WARN  <filename>(<lineNumber>) - "
    cout << dt.toString("hh:mm:ss.zzz") << " " << getLevelString(level) << "  " <<
            filename << "(" << lineNumber << ")" << " - " << str << endl;
  }
}
예제 #4
0
void HtmlLog::logFiltered(const std::string &cat, LogLevel level, const std::string &msg,
                          const std::string &extendedInfo)
{
    if (!file_)
        return;

    std::string output = "\t\t\t<tr bgcolor=\"" + getLevelColor(level) + "\">\n";
    if (dateStamping_)
        output += "\t\t\t\t<td>" + getDateString() + "</td>\n";
    if (timeStamping_)
        output += "\t\t\t\t<td>" + getTimeString() + "</td>\n";
    if (showCat_)
        output += "\t\t\t\t<td>" + cat + "</td>\n";
    if (showLevel_)
        output += "\t\t\t\t" + getLevelString(level) + "\n";
    fputs((output +  "\t\t\t\t<td title=\"" + extendedInfo + "\">" + msg + "</td>\n\t\t\t</tr>\n").c_str(), file_);
    fflush(file_);
}
예제 #5
0
void TextLog::logFiltered(const std::string& cat, LogLevel level, const std::string& msg,
                          const std::string& /*extendedInfo*/)
{
    if (!file_)
        return;

    std::string output = "";
    if (dateStamping_)
        output += "[" + getDateString() + "] ";
    if (timeStamping_)
        output += "[" + getTimeString() + "] ";
    if (showCat_)
        output += cat + " ";
    if (showLevel_)
        output += "(" + getLevelString(level) + ") ";
    if (output != "")
        output += '\t';
    fputs((output +  msg + "\n").c_str(), file_);
    fflush(file_);
}
예제 #6
0
void ConsoleLog::logFiltered(const std::string& cat, LogLevel level, const std::string& msg,
                             const std::string& /*extendedInfo*/)
{
    std::string output;
    if (colorOutput_)
        output = getLevelColor(level);

    if (dateStamping_)
        output += "[" + getDateString() + "] ";
    if (timeStamping_)
        output += "[" + getTimeString() + "] ";
    if (showCat_)
        output += cat + " ";
    if (showLevel_)
        output += "(" + getLevelString(level) + ") ";
    if (output != "")
        output += '\t';

    output += msg;
    if (colorOutput_)
        output += "\033[00m"; // return to default color (Reset all attributes)

    std::cout << output << std::endl;
}
예제 #7
0
void GamePlay::gameOver(float dt) {
//	Director::getInstance()->pause();
	gameState = End;
//invisible frame ready
	if (frameReady != NULL) {
		for (int i = 0; i < SUM_NUM; i++)
			frameReady[i]->setVisible(false);
	}

	boardWin = Sprite::create("board.png");
	boardWin->setPosition(Vec2(-visibleSize.width / 4, visibleSize.height / 2));
	boardWin->setZOrder(30);
	this->addChild(boardWin);
	float haflHeight = boardWin->getContentSize().height / 2;
	float haflWidth = boardWin->getContentSize().width / 2;

	auto jumpto = JumpTo::create(0.5,
			Vec2(visibleSize.width / 2, visibleSize.height / 2 - 3 * PADDING),
			PADDING * 3, 4);
	boardWin->runAction(jumpto);

	updatehightestRecord();

	if (onSound)
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
				"sound/music_win.ogg");
//congratulation
	Sprite* congratulation = Sprite::create("congratulation.png");
	congratulation->setPosition(
			Vec2(haflWidth,
					haflHeight * 2 - 3 * PADDING
							- congratulation->getContentSize().height));
	congratulation->setZOrder(40);
	boardWin->addChild(congratulation);

//highscore
	Sprite* newhighscore = Sprite::create("newhighscore.png");
	newhighscore->setPosition(
			Vec2(haflWidth,
					congratulation->getPositionY()
							- congratulation->getContentSize().height / 2
							- newhighscore->getContentSize().height / 2
							- 2 * PADDING));
	newhighscore->setZOrder(40);
	boardWin->addChild(newhighscore);

	//TODO
	if (timeplay > 0)
		NativeUtils::submitScore(
				getLeaderBoard(GamePlay::instance()->getLevel()),
				timeplay * 1000);
	if (timeplay > highScore) {
		newhighscore->setVisible(false);
	} else {
		newhighscore->setVisible(true);
	}

//gameover text
	Sprite* gameovertext = Sprite::create("gameovertext.png");
	gameovertext->setPosition(
			Vec2(4 * PADDING + gameovertext->getContentSize().width / 2,
					newhighscore->getPositionY()
							- newhighscore->getContentSize().height / 2
							- gameovertext->getContentSize().height / 2
							- 2 * PADDING));
	gameovertext->setZOrder(40);
	boardWin->addChild(gameovertext);

	float sizewidth = gameovertext->getContentSize().width;
	float sizeheight = gameovertext->getContentSize().height;
//show score
	LabelTTF *currentscore = LabelTTF::create("00:00", "fonts/hlvgchac.ttf",
			40);
	currentscore->setZOrder(50);
	currentscore->setColor(Color3B(Color3B::BLUE));
	showTextTime(currentscore, timeplay);
	currentscore->setPositionX(
			sizewidth + PADDING + currentscore->getContentSize().width / 2);
	currentscore->setPositionY(sizeheight / 2);
	gameovertext->addChild(currentscore);

	LabelTTF *highscore = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 40);
	highscore->setZOrder(50);
	highscore->setColor(Color3B(Color3B::BLUE));
	showTextTime(highscore, highScore);
	highscore->setPositionX(
			sizewidth + PADDING + currentscore->getContentSize().width / 2);
	highscore->setPositionY(highscore->getContentSize().height / 2);
	gameovertext->addChild(highscore);

	std::string miniModeSprite = getLevelString(
			GamePlay::instance()->getLevel());
	Sprite* miniMode = Sprite::create("mini" + miniModeSprite + ".png");
	miniMode->setPosition(
			Vec2(
					haflWidth * 2 - miniMode->getContentSize().width / 2
							- 3 * PADDING,
					gameovertext->getPositionY()
							+ miniMode->getContentSize().height / 2
							+ 2 * PADDING));
	boardWin->addChild(miniMode);
//button ok
	MenuItemImage* okBtn = MenuItemImage::create("okBtn.png", "okBtn.png",
			CC_CALLBACK_0(GamePlay::gameCloseWinBoard, this));
	auto okMenu = Menu::create(okBtn, nullptr);
	okMenu->setZOrder(40);
	okMenu->setPosition(
			Vec2(haflWidth / 2 + PADDING,
					gameovertext->getPositionY()
							- gameovertext->getContentSize().height / 2
							- okBtn->getContentSize().height / 2
							- 2 * PADDING));
	boardWin->addChild(okMenu);
//button share
	MenuItemImage* shareBtn = MenuItemImage::create("shareBtn.png",
			"shareBtn.png", CC_CALLBACK_0(GamePlay::gameShareWin, this));
	auto shareMenu = Menu::create(shareBtn, nullptr);
	shareMenu->setZOrder(40);
	shareMenu->setPosition(
			Vec2(haflWidth * 3 / 2 - PADDING, okMenu->getPositionY()));
	boardWin->addChild(shareMenu);
}
예제 #8
0
bool GamePlay::init() {
	if (!Layer::init()) {
		return false;
	}

	gameState = Ready;
	visibleSize = Director::getInstance()->getVisibleSize();
	getSoundMusic();

	//load game AI
	//init array number and computation
	int ARRAY_NUMBER[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	arrNum = gameAI->randomNumber(ARRAY_NUMBER, SUM_NUM);
	for (int i = 0; i < SUM_NUM; i++) {
		arrNUM[i] = arrNum[i];
	}
	char s[SUM_COM] = "";
	//TODO change level
//	arrCOM = gameAI->randomComputation(s, SUM_COM,
//			GamePlay::instance()->getLevel() >= 2 ? 2 : 3);
	arrCOM = gameAI->randomComputation(s, SUM_COM, 2);
	for (int i = 0; i < SUM_COM; i++) {
		arrCOMPUTATE[i] = arrCOM[i];
	}
	for (int i = 0; i < SUM_COM / 2; i++) {
		tempResult[i] = INIT_FRAME;
	}

	int arr[GamePlay::instance()->getLevel()];
	int* arrayLevel = gameAI->randomLessNumber(arr,
			GamePlay::instance()->getLevel());

	//load background
	auto bg = Sprite::create("background.png");
	bg->setAnchorPoint(Vec2(0, 0));
	bg->setPosition(Vec2(0, 0));
	this->addChild(bg, -1);
	float rX = visibleSize.width / bg->getContentSize().width;
	float rY = visibleSize.height / bg->getContentSize().height;
	bg->setScaleX(rX);
	bg->setScaleY(rY);

	//show logo game
	Sprite *logoGame = Sprite::create("smalllogo.png");
	logoGame->setAnchorPoint(Vec2(0.0, 1.0));
	logoGame->setPosition(Vec2(PADDING, visibleSize.height - PADDING));
	logoGame->setTag(TAG_LOGO);
	logoGame->setScale(0.6f);
	this->addChild(logoGame);

	//load frame ready
	float baseY = logoGame->getPositionY()
			- logoGame->getBoundingBox().size.height - PADDING;
	float baseX = PADDING / 2;
	for (int i = 0; i < SUM_NUM; i++) {
		frameReady[i] = Sprite::create("frame.png");
		float width = frameReady[i]->getContentSize().width;
		float height = frameReady[i]->getContentSize().height;
		frameReady[i]->setTag(TAG_START_READY_POINT + i);
		frameReady[i]->setPositionX(baseX + 5.0 / 8.0 * i * width + width / 2);
		if (i % 2 == 0) {
			frameReady[i]->setPositionY(baseY - height / 2);
		} else {
			frameReady[i]->setPositionY(baseY - height);
		}
		this->addChild(frameReady[i]);
	}

	//create frame play
	float paddingY = 0;
	float paddingX = 0;
	for (int i = 0; i < SUM_NUM; i++) {
		float baseX = PADDING;
		framePlay[i] = TouchSprite::create("frame.png");
		framePlay[i]->setTag(TAG_FRAME_PLAY + i);
		paddingX = (visibleSize.width - PADDING * 4
				- framePlay[i]->getContentSize().width) / 3.0;
		framePlay[i]->setPositionX(
				PADDING + framePlay[i]->getContentSize().width / 2
						+ paddingX * (i % 3));

		float baseY = frameReady[0]->getPositionY();
		if (i % 3 == 0)
			paddingY = paddingX * ((int) i / 3 + 1);
		framePlay[i]->setPositionY(baseY - paddingY);
		framePlay[i]->score = 0;
		framePlay[i]->isFixed = false;
		for (int j = 0; j < GamePlay::instance()->getLevel(); j++) {
			if (arrNum[i] == arrayLevel[j]) {
				framePlay[i]->score = arrNum[i];
				//TODO
				framePlay[i]->isFixed = true;
				framePlay[i]->setDisplayFrame(
						SpriteFrame::create(
								"frame" + std::to_string(arrNum[i]) + ".png",
								framePlay[i]->getTextureRect()));
			}
		}
//		CCLog("frameplay[%d] = %d", i, framePlay[i]->score);
		this->addChild(framePlay[i]);
	}

	//load number button
	//TODO
	std::string name = "number";
	MoveTo* actionBy;
	int k = 0;
	for (int i = 0; i < SUM_NUM; i++) {
		numberBtn[i] = TouchSprite::create(
				name + std::to_string(i + 1) + ".png");
		numberBtn[i]->setTag(TAG_NUMBER + i);
		numberBtn[i]->setPositionY(visibleSize.height + 3 * PADDING);
		numberBtn[i]->setPositionX(frameReady[i]->getPositionX());
		numberBtn[i]->setZOrder(10);
		numberBtn[i]->isHidden = false;
		this->addChild(numberBtn[i]);
		actionBy = MoveTo::create(0.4, frameReady[i]->getPosition());
		auto easeAction = EaseBounceInOut::create(actionBy);

		for (int j = 0; j < GamePlay::instance()->getLevel(); j++) {
			if ((i + 1) == arrayLevel[j]) {
				numberBtn[i]->isHidden = true;
				numberBtn[i]->setVisible(false);
			}
		}

		if (numberBtn[i]->isHidden == false) {
			auto delay = DelayTime::create(0.2 * (k + 1));
			auto sequence = Sequence::create(delay, easeAction, nullptr);
			numberBtn[i]->runAction(sequence);
			k++;
		}
	}

	if (frameReady != NULL) {
		for (int i = 0; i < SUM_NUM; i++)
			frameReady[i]->setVisible(false);
	}

	//create result frame and equal character
	Sprite* frameEqual[SUM_COM / 2];
	Sprite* characterEqual[SUM_COM / 2];
	for (int i = 0; i < SUM_COM / 2; i++) {
		characterEqual[i] = Sprite::create("icon_equal.png");
		frameEqual[i] = Sprite::createWithTexture(frameReady[i]->getTexture());
		frameEqual[i]->setTag(TAG_FRAME_EQUAL + i);
		if (i % 2 == 0) {
			//frame equal
			frameEqual[i]->setPositionY(
					framePlay[SUM_NUM - 1]->getPositionY()
							+ paddingX * (2 - (int) i / 2));
			frameEqual[i]->setPositionX(
					framePlay[SUM_NUM - 1]->getPositionX() + paddingX);
			//character equal
			characterEqual[i]->setPositionY(
					framePlay[SUM_NUM - 1]->getPositionY()
							+ paddingX * ((int) i / 2));
			characterEqual[i]->setPositionX(
					framePlay[SUM_NUM - 1]->getPositionX() + paddingX / 2);
		} else {
			//frame equal
			frameEqual[i]->setPositionY(
					framePlay[SUM_NUM - 1]->getPositionY() - paddingX);
			frameEqual[i]->setPositionX(
					framePlay[SUM_NUM - 1]->getPositionX()
							- paddingX * (2 - (int) i / 2));
			//character equal
			characterEqual[i]->setPositionY(
					framePlay[SUM_NUM - 1]->getPositionY() - paddingX / 2);
			characterEqual[i]->setPositionX(
					framePlay[SUM_NUM - 1]->getPositionX()
							- paddingX * (2 - (int) i / 2));
		}
		this->addChild(frameEqual[i]);
		this->addChild(characterEqual[i]);
	}

	//position of character computation
	Sprite* plusSprite = Sprite::create("icon_plus.png");
	Sprite* minusSrite = Sprite::create("icon_minus.png");
	Sprite* mutiplySprite = Sprite::create("icon_multiply.png");
	Sprite* divideSprite = Sprite::create("icon_divide.png");

	for (int i = 0; i < SUM_COM; i++) {
		if (arrCOM[i] == '+')
			comBtn[i] = Sprite::createWithTexture(plusSprite->getTexture());
		else if (arrCOM[i] == '-')
			comBtn[i] = Sprite::createWithTexture(minusSrite->getTexture());
		else if (arrCOM[i] == '*')
			comBtn[i] = Sprite::createWithTexture(mutiplySprite->getTexture());
		else if (arrCOM[i] == '/')
			comBtn[i] = Sprite::createWithTexture(divideSprite->getTexture());
		this->addChild(comBtn[i]);
	}
	setPosCharacterBtn(comBtn, framePlay, paddingX);

	//calculate result
	result[0] = gameAI->calculate(arrNum[0], arrNum[1], arrNum[2], arrCOM[0],
			arrCOM[1]);
	result[1] = gameAI->calculate(arrNum[0], arrNum[3], arrNum[6], arrCOM[2],
			arrCOM[7]);
	result[2] = gameAI->calculate(arrNum[3], arrNum[4], arrNum[5], arrCOM[5],
			arrCOM[6]);
	result[3] = gameAI->calculate(arrNum[1], arrNum[4], arrNum[7], arrCOM[3],
			arrCOM[8]);
	result[4] = gameAI->calculate(arrNum[6], arrNum[7], arrNum[8], arrCOM[10],
			arrCOM[11]);
	result[5] = gameAI->calculate(arrNum[2], arrNum[5], arrNum[8], arrCOM[4],
			arrCOM[9]);
	gameAI->printArray(result, SUM_COM / 2);

	//set result to frameEqual
	for (int i = 0; i < SUM_COM / 2; i++) {
		resultLabel[i] = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 48);
		resultLabel[i]->setColor(Color3B(Color3B::RED));
		resultLabel[i]->setString(std::to_string(result[i]));
		resultLabel[i]->setPosition(frameEqual[i]->getPosition());
		this->addChild(resultLabel[i]);
	}

	//button pause
	Sprite* pauseGame = Sprite::create("pauseBtn.png");
	Sprite* pauseGame_press = Sprite::create("pauseBtn_press.png");
	MenuItemSprite* pauseBtn = MenuItemSprite::create(pauseGame,
			pauseGame_press, NULL, CC_CALLBACK_0(GamePlay::gamePause, this));
	Menu *menuPause = Menu::create(pauseBtn, nullptr);
	menuPause->setPosition(
			Vec2(
					visibleSize.width - PADDING
							- pauseBtn->getContentSize().width / 2,
					visibleSize.height - PADDING
							- pauseBtn->getContentSize().height / 2));
	menuPause->setTag(TAG_PAUSE_BTN);
	this->addChild(menuPause);

	//time in pause button
	LabelTTF *currenttime = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 40);
	Point timePoint = menuPause->getPosition();
	currenttime->setPosition(
			Vec2(timePoint.x - PADDING * 2, timePoint.y + 7.0 / 4.0 * PADDING));
	currenttime->setZOrder(10);
	currenttime->setColor(Color3B(Color3B::RED));
	currenttime->setTag(TAG_LABEL_COUNT_TIME);
	this->addChild(currenttime);

	std::string miniModeSprite = getLevelString(
			GamePlay::instance()->getLevel());
	Sprite* miniMode = Sprite::create("mini" + miniModeSprite + ".png");
	miniMode->setScale(0.5);
	miniMode->setPosition(
			Vec2(currenttime->getPositionX(),
					currenttime->getPositionY()
							- currenttime->getContentSize().height
							- PADDING / 2));
	this->addChild(miniMode);

	//board menu pause
	boardMenuPause = Sprite::create("board.png");
	boardMenuPause->setPosition(
			Vec2(visibleSize.width / 2,
					visibleSize.height
							+ boardMenuPause->getContentSize().height / 2
							+ PADDING));
	boardMenuPause->setZOrder(30);
	this->addChild(boardMenuPause);

	//button help of menu
	Sprite* helpbtn = Sprite::create("help1.png");
	Sprite* helpbtn_press = Sprite::create("help2.png");
	MenuItemSprite* helpBtn = MenuItemSprite::create(helpbtn, helpbtn_press,
	NULL, CC_CALLBACK_0(GamePlay::gameHelp, this));
	Menu *menuHelp = Menu::create(helpBtn, nullptr);
	menuHelp->setPosition(
			Vec2(boardMenuPause->getContentSize().width / 2,
					boardMenuPause->getContentSize().height
							- helpbtn->getContentSize().height));
	boardMenuPause->addChild(menuHelp);

	//button setting of menu
	Sprite* setbtn = Sprite::create("settings1.png");
	Sprite* setbtn_press = Sprite::create("settings2.png");
	MenuItemSprite* setBtn = MenuItemSprite::create(setbtn, setbtn_press, NULL,
			CC_CALLBACK_0(GamePlay::gameSetting, this));
	Menu *menuSetting = Menu::create(setBtn, nullptr);
	menuSetting->setPosition(
			Vec2(boardMenuPause->getContentSize().width / 2,
					menuHelp->getPositionY() - setbtn->getContentSize().height
							- PADDING));
	menuSetting->setTag(TAG_SETTING);
	boardMenuPause->addChild(menuSetting);

	//button quit of menu
	Sprite* quitbtn = Sprite::create("quit1.png");
	Sprite* quitbtn_press = Sprite::create("quit2.png");
	MenuItemSprite* quitBtn = MenuItemSprite::create(quitbtn, quitbtn_press,
	NULL, CC_CALLBACK_0(GamePlay::gameQuit, this));
	Menu *menuQuit = Menu::create(quitBtn, nullptr);
	menuQuit->setPosition(
			Vec2(menuSetting->getPositionX(),
					menuSetting->getPositionY()
							- quitbtn->getContentSize().height - PADDING));
	menuQuit->setTag(TAG_QUIT);
	boardMenuPause->addChild(menuQuit);

	//button replay, resume, share
	MenuItemImage* resumeBtn = MenuItemImage::create("menu_resume.png",
			"menu_resume.png", CC_CALLBACK_0(GamePlay::gameResume, this));
	auto menuResume = Menu::create(resumeBtn, nullptr);
	menuResume->setPosition(
			Vec2(menuSetting->getPositionX(),
					menuQuit->getPositionY()
							- resumeBtn->getContentSize().height - PADDING));
	boardMenuPause->addChild(menuResume);

	MenuItemImage* replayBtn = MenuItemImage::create("menu_replay.png",
			"menu_replay.png", CC_CALLBACK_0(GamePlay::gameReplay, this));
	auto menuReplay = Menu::create(replayBtn, nullptr);
	menuReplay->setPosition(
			Vec2(
					menuResume->getPositionX()
							- resumeBtn->getContentSize().width - PADDING,
					menuResume->getPositionY()));
	boardMenuPause->addChild(menuReplay);

	MenuItemImage* shareBtn = MenuItemImage::create("menu_share.png",
			"menu_share.png",
			CC_CALLBACK_0(GamePlay::gameShareCloseMenuPause, this));
	auto menuShare = Menu::create(shareBtn, nullptr);
	menuShare->setPosition(
			Vec2(
					menuResume->getPositionX()
							+ resumeBtn->getContentSize().width + PADDING,
					menuResume->getPositionY()));
	boardMenuPause->addChild(menuShare);

	auto event_listener = EventListenerTouchOneByOne::create();
	auto dispatcher = Director::getInstance()->getEventDispatcher();
	event_listener->setSwallowTouches(true);
	event_listener->onTouchBegan = CC_CALLBACK_2(GamePlay::onTouchBegan, this);
	event_listener->onTouchMoved = CC_CALLBACK_2(GamePlay::onTouchMoved, this);
	event_listener->onTouchEnded = CC_CALLBACK_2(GamePlay::onTouchEnded, this);
	dispatcher->addEventListenerWithSceneGraphPriority(event_listener, this);
	this->setKeypadEnabled(true);
	this->scheduleUpdate();
//	this->schedule(schedule_selector(GamePlay::update), 1.0f);
	gameState = Playing;
	return true;
}
예제 #9
0
// this should not throw exception since it is called often in a 
// catch block to log an error resulting from an exception.
void Log::vlog(ModuleId module, Level level, const char *format,
	       std::va_list args) 
    throw()
{
    if (initialized) {
	if (module >= moduleList->size()) {
	    module = ALL_MODULES;
	}

        char *logMsg = PR_vsmprintf(format, args);
	// call user defined logger if any.
	if (loggerFunc != NULL) {
	    loggerFunc((*moduleList)[module].name.c_str(),  
		       static_cast<am_log_level_t>(static_cast<int>(level)),
		       logMsg);
	}

	// do default log.
	if ((*moduleList)[module].level >= level) {

	    // format: 
	    // year-month-day hour:min:sec.usec level pid:thread module: msg
	    // get level string		
	    std::size_t levelLabelIndex = getLevelString(level);
	    char levelStr[50]; 
	    PRUint32 llen;
	    if (levelLabelIndex < numLabels) {
		llen = PR_snprintf(levelStr, sizeof(levelStr),
				       "%s", levelLabels[levelLabelIndex]);
	    } else {
		llen = PR_snprintf(levelStr, sizeof(levelStr), "%d", level);
	    }

	    if (llen > 0) { 
		// get time.
		PRExplodedTime now;
		PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &now);
    
		// format header and msg.
		PRUint32 len;
		char hdr[100];
		len = PR_snprintf(hdr, sizeof(hdr), 
				  "%d-%02d-%02d %02d:%02d:%02d.%03d"
				  "%8s %u:%p %s: %%s\n",
				  now.tm_year, now.tm_month+1, now.tm_mday,
				  now.tm_hour, now.tm_min, now.tm_sec, 
				  now.tm_usec / 1000,
				  levelStr,
				  getpid(), PR_GetCurrentThread(),
				  (*moduleList)[module].name.c_str());
		if (len > 0) {
                  if (logRotation) {
                    if ((currentLogFileSize + 1000) < maxLogFileSize) {
		       std::fprintf(logFile, hdr, logMsg);
		       std::fflush(logFile);
                    } else {
    		      ScopeLock scopeLock(*lockPtr);
                      currentLogFileSize = ftell(logFile);
                      if ((currentLogFileSize + 1000) > maxLogFileSize) {
                         // Open a new log file
	                 if (!pSetLogFile(logFileName)) {
		                 log(ALL_MODULES, LOG_ERROR,
		                 "Unable to open log file: '%s', errno = %d",
		                 logFileName.c_str(), errno);
	                }
                      }
		      std::fprintf(logFile, hdr, logMsg);
		      std::fflush(logFile);
                    }
                    currentLogFileSize = ftell(logFile);
                  } else {
		      std::fprintf(logFile, hdr, logMsg);
		      std::fflush(logFile);
                  }
		}
	     }
	}

	// Remote Logging starts here.
	if (module == remoteModule) {
	    if (remoteInitialized) {
		bool doLogRemotely = 
		    ((*moduleList)[module].level >= Log::LOG_AUTH_REMOTE) &&
		    ((*moduleList)[module].level & level);

		if (doLogRemotely) {
		    am_status_t status;
		    status = rmtLogSvc->logMessage(logMsg);
		    if(status != AM_SUCCESS) {
			Log::log(Log::ALL_MODULES, Log::LOG_ERROR,
			    "Log::vlog(): Error logging message [%s] "
			    "to remote server. Error: %s.", 
			    logMsg, am_status_to_string(status));
		    }
		}
	    } else {
		Log::log(Log::ALL_MODULES, Log::LOG_ERROR,
		    "Log::vlog(): Remote logging service not initialized. "
		    "Cannot log message to remote server.");
	    }
	}
	PR_smprintf_free(logMsg);
    }
    return;
}
예제 #10
0
파일: Log.cpp 프로젝트: LeoYangLing/Client
void Log::output(const char *file, int line, Log::Level level, Log::Group group, const char *format, ...)
{
	int outputType = getActiveOutput(level, group);
	if(outputType == None)
		return;
	
	static char logtime[LOGTIME_SIZE];
	time_t now = time(0);
	strftime(logtime, sizeof(logtime), LOGTIME_FORMAT, localtime(&now));
	
	//write to buffer
    char jsonBuf[kLogMaxLogLen+1] = {0};
    
    if(outputType & Console || outputType & File)
    {
        snprintf(jsonBuf, kLogMaxLogLen, "TIME=%s LEVEL=%s GROUP=%s FILE=%s LINE=%d: ",logtime, getLevelString(level),getGroupString(group), getBaseName(file), line);
        
        size_t bufferMaxLength = kLogMaxLogLen-strlen(jsonBuf)-1;
        if(bufferMaxLength > 0)
        {
        #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
            va_list ap;
            va_start(ap, format);
            vsnprintf_s(jsonBuf+strlen(jsonBuf), kLogMaxLogLen, kLogMaxLogLen, format, ap);
            va_end(ap);
        #else
            va_list ap;
            va_start(ap, format);
            vsnprintf(jsonBuf+strlen(jsonBuf), kLogMaxLogLen, format, ap);
            va_end(ap);
        #endif
            
            sprintf(jsonBuf+strlen(jsonBuf), "\n");
        }
        

        
        //write buffer to console
        if(outputType & Console)
        {
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
        __android_log_print(ANDROID_LOG_INFO, "LuckyCasino:","%s",jsonBuf);
    #else
        printf("%s",jsonBuf);
    #endif
        }
        
        if(outputType & File)
        {
            assert(m_outfileHandle);
            fwrite(jsonBuf, strlen(jsonBuf), 1, m_outfileHandle);
            fflush(m_outfileHandle);
        }
    }
	
	if(outputType & Network)
	{
        Json::Value jcontent;
        JsonStream jstream(jcontent);
        jstream.push("TIME", std::string(logtime));
        jstream.push("UDID", Utils::getUDID());
        jstream.push("PID", PlayerMan::getInstance().getPlayerId());
        jstream.push("LOGContent", std::string(jsonBuf));
        
        Json::Value root;
        JsonStream jrootstream(root);
        jrootstream.push("type", std::string(getGroupString(group)));
        jrootstream.push("value", jcontent);
        
		ScopedMutex _locker(m_mutexBuffer);
		m_networkBufList.push_back(root);
	}
}
예제 #11
0
 StringLogObject(const std::string& obj, LogLevel l) : _obj(obj)
 {
     _timeStamp = boost::posix_time::microsec_clock::local_time();
     getLevelString(l, _levelStr);
 }
예제 #12
0
 LogObject(TSmartPtr obj, LogLevel l) : _obj(obj)
 {
     _timeStamp = boost::posix_time::microsec_clock::local_time();
     getLevelString(l, _levelStr);
 }