Developers Manual > Cocos2d-x > Modules > Debugging > How to use CCLOG

How to use CCLOG

Introduction

CCLOG can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested.

NOTE: CCLOG is not as powerful as NSLog on OS X. You cannot use CCLog if you don’t know how to format output.

Turn on the Marcos

CCLOG is enabled while COCOS2D_DEBUG is defined as 1.

1
#define COCOS2D_DEBUG 1

Visual Studio

For people wanting to check their preprocessor macros in visual studio, right click the project in the project manager-> click properties-> select configuration properties-> C/C++ -> Preprocessor. You will have the preprocessor definitions in the right .

Parameters

Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument:

Sample Code

C++

1
2
3
4
5
6
7
CCLOG("Characters: %c %c", 'a', 65);
CCLOG("Decimals: %d %ld", 1977, 650000L);
CCLOG("Preceding with blanks: %10d", 1977);
CCLOG("Preceding with zeros: %010d", 1977);
CCLOG("Some different radixes: %d %x %o %#x %#o", 100, 100, 100, 100, 100);
CCLOG("Floats: %4.2f %.0e %E", 3.1416, 3.1416, 3.1416);
CCLOG("%s","A string");

Lua
CCLOG is not bound to Lua, you can use print instead or define a new function to accomplish the same utility.

1
2
3
4
5
6
7
cclog = function(...)
    print(string.format(...))
end

cclog("float and int and string: %4.2f, %#x, %s", 3.1415926, 2014, "cocos2d-x");
print("you can use either print or cclog as you want");
print("another float is " .. 3.14 .. " another int is " .. 1024);

Output

C++

cocos2d: Characters: a A
cocos2d: Decimals: 1977 650000
cocos2d: Preceding with blanks:       1977
cocos2d: Preceding with zeros: 0000001977
cocos2d: Some different radixes: 100 64 144 0x64 0144
cocos2d: Floats: 3.14 3e+00 3.141600E+00
cocos2d: A string

Lua

cocos2d: [LUA-print] float and int and string: 3.14, 0x7de, cocos2d-x
cocos2d: [LUA-print] you can use either print or cclog as you want
cocos2d: [LUA-print] another float is 3.14 another int is 1024

argument.png (151.1 kB) iven, 2013-02-25 07:57

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.