Solved

using C macros to print line number and function name

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

776 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