Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using C macros to print line number and function name

Posted on 2013-12-24
1
Medium Priority
?
345 Views
Last Modified: 2014-02-04
Hi there,
I am using log4c library and have been using the following macro for my logging purposes.

#define mylog(A,B, ...) log4c_category_log(A, B, __VA_ARGS__)

It works fine, but I want to also use __LINE__, __FUNC__ directives so I can have the line number and function name printed.

For example, if I am using the mylog( ) in my_function() in line 25.

void my_function()
{
    mylog(MYCATEGORY, LOG4C_PRIORITY_ERROR, "some message");
}

I want the log to be printed like :
>>>>>>some message, my_function, 25
I don't want to edit the logging but rather using the macro definition be able to print these details.  Is it possible?

I tried the following, but it does not work when the log is something like:
 mylog(MYCATEGORY, LOG4C_PRIORITY_ERROR, "some message %s  %s", "value1", "value2");

#define mylog(A,B, ...) log4c_category_log(A, B,"%s %s %d ", __VA_ARGS__, __FUNCTION__, __LINE__)
0
Comment
Question by:ambuli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 39738341
#define mylog(A,B, ...) log4c_category_log(A, B, __VA_ARGS__,__LINE__)
#define log4c_category_log(A,B,C,...) printf(">>>>>>" C ", " __FILE__ ", %d\n", __VA_ARGS__)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question