In my iOS project, I use one 3rd-party library, which is is incredible spamming into the console output. Can I apply any filtering to debug output.
-
1It may not be a real solution but [MCLog](https://github.com/yuhua-chen/MCLog) is a XCode plugin enabling output filtering. – david Sep 02 '15 at 16:29
-
@david Thx, I should accept this comment as best answer, because `MCLog` do exactly what I need. – ArtFeel Sep 04 '15 at 14:01
-
l've copied my comment as an answer then. – david Sep 04 '15 at 14:27
4 Answers
If the library is using NSLog you can redefine it and discard the log message when it comes from the library. Example code:
#define NSLog(args...) [[Logger singleton] debugWithLevel:kDebug line:__LINE__ funcName:__PRETTY_FUNCTION__ message:args];
// poor man's nslog
@interface Logger : NSObject
typedef enum {
kTrace=0, kDebug=1, kInfo=2, kWarn=3, kError=4, KSilent=5
} LoggerLevel;
// ...
@implementation Logger
+(Logger *)singleton {
static dispatch_once_t pred;
static Logger *shared = nil;
dispatch_once(&pred, ^{
shared = [[Logger alloc] init];
shared.logThreshold = kTrace;
});
return shared;
}
-(void) debugWithLevel:(LoggerLevel)level
line:(int)line
funcName:(const char *)funcName
message:(NSString *)msg, ... {
va_list ap;
va_start (ap, msg);
msg = [[[NSString alloc] initWithFormat:msg arguments:ap] autorelease];
va_end (ap);
msg = [NSString stringWithFormat:@"%s %50s:%3d - %@", levelName[level], funcName, line, msg];
// ... filter by class name ...
fprintf(stdout,"%s\n", [msg UTF8String]);
}
@end
Note that funcName
contains the classname and method sending the message. If the library is a good citizen and has classes that start with a prefix, discard the output if the className starts with that. Otherwise you have to load a list of classes from that library and check them before the fprintf line.
This of course, doesn't duplicate the log to syslogd like NSLog does, but who cares. :P

- 62,815
- 21
- 164
- 192
Works in Xcode 5.0 through 7.3, Apple no longer supports Xcode plug-ins as of Xcode 8.0.
MCLog should be what you're looking for.
This is an XCode plugin.

- 1,311
- 12
- 32
-
1yeah... not working anymore. github issues state the same and no one seems to care – Radu Simionescu Jun 01 '16 at 09:58
It depends if you're using directly the 3rd party library source code in your project or a binary library.
If you're using the source code I'd suggest to check what they are using to log the messages. It may have a way to reduce the verbosity. If they are using plain NSLog
the only option would be to redefine NSLog
in order to do some filtering, as Jano proposed you.
If they are using low level functions like printf
and the like, your best option is to replace them with your own custom logging macro, like:
#ifdef DEBUG_3P
#define LOG_3P(str) NSLog(@"%s", str)
#else
#define LOG_3P(str) /* nothing */
#endif
Then, replace printf("a c string message")
with LOG_3P("a c string message")
. You'll need to customize the solution, adjust macro parameters or even add several macros for your case. And make a few search and replace until it works.
When you want to see the 3rd party library logs, just define DEBUG_3P
in your build settings as C flags: -D DEBUG_3P
, otherwise it will be mute.
If you're using a binary library you can just build it with its release configuration, disabling or reducing the logs verbosity to its minimum.

- 19,551
- 4
- 71
- 68
-
I use source code library written in C, and it uses printf(), vprintf() and puts() for logging. – ArtFeel Oct 26 '11 at 11:55
-
In that case, unless you replace them with your own logging macro, I'm afraid you can't *easily* intercept the output. See my updated answer. – djromero Oct 26 '11 at 12:16
For Swift, I wrote a wrapper around print() that does just this. See here: https://github.com/SebastianMecklenburg/TagLog
It works by adding tags to debug messages and then filter the output by those tags. It works all in code and doesn't need an Xcode plugin.
-
Will this filter out 3rd party text that's sent to the console via the `print()` command? – Mihai Fratu Sep 13 '16 at 08:58
-
1