Skip to content

Instantly share code, notes, and snippets.

@marciniwanicki
Last active August 29, 2015 14:09
Show Gist options
  • Save marciniwanicki/e02f1281b4e86ef90f4f to your computer and use it in GitHub Desktop.
Save marciniwanicki/e02f1281b4e86ef90f4f to your computer and use it in GitHub Desktop.
Extension for DDLog (CocoaLumberjack) allows to define own log areas.
//
// MILog.h
//
// Copyright (c) 2014 Marcin Iwanicki
//
/**
// example:
#define HTTP_CLIENT_LOGGER true
#define DAO_LOGGER false
MILogInfo(HTTP_CLIENT_LOGGER, @"This message will be logged.");
MILogInfo(DAO_LOGGER, "This message will be ignored as DAO_LOGGER is set to false.");
*/
#import "DDLog.h"
#ifndef Logger_MILog_h
#define Logger_MILog_h
#pragma mark - Error
#define MILogError(area, frmt, ...) _MILogError_private(area, frmt, ##__VA_ARGS__)
#define _MILogError_private(area, frmt, ...) _MILogError_##area(frmt, ##__VA_ARGS__)
#define _MILogError_true(frmt, ...) DDLogError(frmt, ##__VA_ARGS__)
#define _MILogError_1(frmt, ...) DDLogError(frmt, ##__VA_ARGS__)
#define _MILogError_false(frmt, ...)
#define _MILogError_0(frmt, ...)
#pragma mark - Warn
#define MILogWarn(area, frmt, ...) _MILogWarn_private(area, frmt, ##__VA_ARGS__)
#define _MILogWarn_private(area, frmt, ...) _MILogWarn_##area(frmt, ##__VA_ARGS__)
#define _MILogWarn_true(frmt, ...) DDLogWarn(frmt, ##__VA_ARGS__)
#define _MILogWarn_1(frmt, ...) DDLogWarn(frmt, ##__VA_ARGS__)
#define _MILogWarn_false(frmt, ...)
#define _MILogWarn_0(frmt, ...)
#pragma mark - Info
#define MILogInfo(area, frmt, ...) _MILogInfo_private(area, frmt, ##__VA_ARGS__)
#define _MILogInfo_private(area, frmt, ...) _MILogInfo_##area(frmt, ##__VA_ARGS__)
#define _MILogInfo_true(frmt, ...) DDLogInfo(frmt, ##__VA_ARGS__)
#define _MILogInfo_1(frmt, ...) DDLogInfo(frmt, ##__VA_ARGS__)
#define _MILogInfo_false(frmt, ...)
#define _MILogInfo_0(frmt, ...)
#pragma mark - Debug
#define MILogDebug(area, frmt, ...) _MILogDebug_private(area, frmt, ##__VA_ARGS__)
#define _MILogDebug_private(area, frmt, ...) _MILogDebug_##area(frmt, ##__VA_ARGS__)
#define _MILogDebug_true(frmt, ...) DDLogDebug(frmt, ##__VA_ARGS__)
#define _MILogDebug_1(frmt, ...) DDLogDebug(frmt, ##__VA_ARGS__)
#define _MILogDebug_false(frmt, ...)
#define _MILogDebug_0(frmt, ...)
#pragma mark - Verbose
#define MILogVerbose(area, frmt, ...) _MILogVerbose_private(area, frmt, ##__VA_ARGS__)
#define _MILogVerbose_private(area, frmt, ...) _MILogVerbose_##area(frmt, ##__VA_ARGS__)
#define _MILogVerbose_true(frmt, ...) DDLogVerbose(frmt, ##__VA_ARGS__)
#define _MILogVerbose_1(frmt, ...) DDLogVerbose(frmt, ##__VA_ARGS__)
#define _MILogVerbose_false(frmt, ...)
#define _MILogVerbose_0(frmt, ...)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment