Debug Log with cocos run

Is it possible to debug and watch cclog in console in windows?

For example, if I don’t want to build with Visual Studio but I build using cocos console:
cocos run -p win32

Is it possible to view CCLog in console?

I’m not sure if it’ll work outside VS, but I use the following to launch with console on windows.

$(projectDir)/proj.win32/main.cpp

#include "main.h"
#include "AppDelegate.h"
#include "cocos2d.h"

USING_NS_CC;

int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // create the application instance
    AppDelegate app;

	// initialize director early so we can edit the size of the window
	auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	if (!glview) {
		glview = GLView::createWithRect("MyApp", Rect(0,0,1280,720), 0.7f);
		director->setOpenGLView(glview);
	}

	/* create console and pipe debug info to it */
	AllocConsole();
	AttachConsole(GetCurrentProcessId());
	freopen("CONIN$", "r", stdin);
	freopen("CONOUT$", "w", stdout);
	freopen("CONOUT$", "w", stderr);
	//freopen("debug_out.txt", "w+",stdout);
	//freopen("debug_out.txt", "w+",stderr);

	int r = -1;
	try
	{
		r = Application::getInstance()->run();
	}
	catch (...)
	{
		printf("___CRASH___");
	}
	/*automatically close the console - we probably don't want this incase of a crash */
	FreeConsole();
	fclose(stdout);
	fclose(stderr);

	return r;
}

Hope this helps!

2 Likes

OMG.

Great, it works without any problem.

Thank you very much! :smiley:

Yay! No problem :stuck_out_tongue: