Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicting definitions with CocoaLumberjack (using Carthage) #531

Open
silverhammermba opened this issue May 23, 2019 · 5 comments
Open

Comments

@silverhammermba
Copy link

Short description

I can't get this to work with an app that is already using CocoaLumberjack 3.5.3 via Carthage because it causes conflicting definitions.

I set up my logging like this in Logging.h

#define LOG_LEVEL_DEF ddLogLevel
@import CocoaLumberjack;
static const DDLogLevel ddLogLevel = DDLogLevelError;

Then in my view controller

#import "Logging.h"
@import MQTTClient;
//...
- (void)viewDidLoad {
    [super viewDidLoad];
    DDLogError(@"error!");
}

That DDLogError gives me two errors:

  1. "Reference to 'ddLogLevel' is ambiguous". It sees two definitions: one is the constant I defined, the other one is extern DDLogLevel ddLogLevel; from MQTTLog.h
  2. "Ambiguous expansion of macro 'DDLogError'". It sees two definitions: one is the correct one from CocoaLumberjack, the other one is this shim from MQTTLog.h #define DDLogError if (ddLogLevel & DDLogFlagError) NSLog

If I remove the @import MQTTClient; it builds and logging works. If I remove the #import "Logging.h" it also builds, but I can see that it isn't using CocoaLumberjack because it no longer respects my logging level.

Environment

  • Operating system: iOS
  • Package Manager: Carthage
  • MQTTClient version: 0.15.2

Steps to reproduce

  1. Create a single view app
  2. Add CocoaLumberjack and MQTTClient via Carthage
  3. Add some DDLog calls
  4. In the same file where you are using DDLog, @import MQTTClient;

Expected behaviour

There should be some way to import CocoaLumberjack and MQTTClient via Carthage and have MQTTClient use my CocoaLumberjack config.

Actual behaviour

Currently I can only find a way to use one or the other, not both.

Other information

I see that there's a #ifdef LUMBERJACK in MQTTLog.h. I tried adding #define LUMBERJACK before I import MQTTClient, but it makes no difference. What does work is if I actually delete the contents of MQTTLog.h, then it builds fine.

Also, not sure if related, even when I import MQTTClient on its own, I can't get it to log anything. For example, I see that it's supposed to log an error if I try to open an base MQTTTransport instance, but I don't see those logs appearing.

@jcavar
Copy link
Contributor

jcavar commented May 28, 2019

Hello, thanks for your feedback, can you try this:

#undef LOG_LEVEL_DEF
#define LOG_LEVEL_DEF myLogLevel
static const int myLogLevel = DDLogLevelVerbose;

[MQTTLog setLogLevel:myLogLevel];

@VincentSit
Copy link

This approach does not work for me. I have my ddLogLevel in the pch file.

@VincentSit
Copy link

Temporary workaround:

Remove #import <MQTTClient/MQTTLog.h> from MQTTClient.h.

If you need to set the LogLevel:

[NSClassFromString(@"MQTTLog") performSelector:@selector(setLogLevel:) withObject:@(ddLogLevel)];

@silverhammermba
Copy link
Author

silverhammermba commented Jun 27, 2019

@jcavar Your suggestion doesn't work. That does enable logging, but it isn't using CocoaLumberjack. I verified by setting breakpoints that it's just using MQTT's shim macros and never hitting any DDLog method.

@ackratos
Copy link

ackratos commented Nov 8, 2019

Temporary workaround:

Remove #import <MQTTClient/MQTTLog.h> from MQTTClient.h.

If you need to set the LogLevel:

[NSClassFromString(@"MQTTLog") performSelector:@selector(setLogLevel:) withObject:@(ddLogLevel)];

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants