Cocoalumberjack: Cannot Call DDLog variants from plain C code

Created on 30 Oct 2014  路  5Comments  路  Source: CocoaLumberjack/CocoaLumberjack

A significant portion of my project is C-based, and I would like to use CocoaLumberjack for logging there. However, updating my prefix header to include CocoaLumberjack in plain C files causes endless headaches about Objective C types not existing.

I switch the types of the files to Objective-C++ , but get these errors upon attempting to call "DDLogVerbose":

/.../MDSystem.c:54:2: Cannot initialize a parameter of type 'DDLogLevel' with an lvalue of type 'const int'

On this line, to test, I had written this code:
DDLogVerbose(@"Hello, world!");

Does anyone know what might be causing these issues? Is there some special macros for logging directly from plain C code?

Most helpful comment

I've resolved this issue. Instead of declaring ddLogLevel global in the prefix header as a const int, it should be declared of type const DDLogLevel as follows:

static const DDLogLevel ddLogLevel = LOG_LEVEL_VERBOSE;

This avoids the implicit typecast issues in the macros, and does not necessitate modifications of the framework itself.

All 5 comments

Can you share a sample project we can debug on?

I have uploaded an example project here. It is a console application targeting Yosemite, with an Objective C main function, and a C function in an Objective-C++ file that should print debug output as well.

However, this is the error log from Xcode:
screen shot 2014-10-29 at 21 14 52

I'm hoping this helps pinpoint the cause of this issue.

Have you tried the CLI Demo project?

I've resolved this issue. Instead of declaring ddLogLevel global in the prefix header as a const int, it should be declared of type const DDLogLevel as follows:

static const DDLogLevel ddLogLevel = LOG_LEVEL_VERBOSE;

This avoids the implicit typecast issues in the macros, and does not necessitate modifications of the framework itself.

:+1:

Was this page helpful?
0 / 5 - 0 ratings