Help us understand the problem. What is going on with this article?

Xcode5のターミナルのログ出力に色をつける

More than 5 years have passed since last update.

Xcodeのログ出力は色がついていないので大変読みづらかったので解決方法をさがしてみました.
結果このように色がつきます.

Screen Shot 2013-11-22 at 15.02.11.png

1. Xcode Colorsをインストールする

https://github.com/robbiehanson/XcodeColors

github から最新のコードを cloneしてビルドしてください.
このときターゲットをTestXcodeColorsにして実行することで
無事インストールができているかの確認ができます.

2. ログ用のマクロを定義

pchなどで定義します.
github本体に例示されているマクロでは動かなかったので一部修正しました.

// XcodeColors
#define XCODE_COLORS_ESCAPE_MAC @"\033["
#define XCODE_COLORS_ESCAPE  XCODE_COLORS_ESCAPE_MAC

#define XCODE_COLORS_RESET_FG  XCODE_COLORS_ESCAPE @"fg;" // Clear any foreground color
#define XCODE_COLORS_RESET_BG  XCODE_COLORS_ESCAPE @"bg;" // Clear any background color
#define XCODE_COLORS_RESET     XCODE_COLORS_ESCAPE @";"   // Clear any foreground or background color

// Debug
#ifdef DEBUG
#define DLOG(format, ...) NSLog(( XCODE_COLORS_ESCAPE @"fg255,0,255;" @"%s:%d: \n" XCODE_COLORS_RESET\
 XCODE_COLORS_ESCAPE @"fg0,0,255;" format XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define DLOG(format, ...)
#endif

3. 呼び出し

DLOG(@"test");

出力結果

このように色がつきます.

Screen Shot 2013-11-22 at 15.02.11.png

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away