Solved

using C macros to print line number and function name

Posted on 2013-12-24
1
343 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 500 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.

707 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