Solved

create a function to encapsulate log4cpp stream

Posted on 2013-12-07
4
293 Views
Last Modified: 2013-12-09
I am using to log the statement under warn priority with the following statement

log4cpp::Category::getRoot() << log4cpp::Priority::WARN << "This is my first PVLogger fatal Message";

I wonder if it is possible to create a overload of << operator so I can write the above statement like below statement


StreamWarm  << "This is my first PVLogger fatal Message";

and StreamWarm incorporate log4cpp::Category::getRoot() << log4cpp::Priority::WARN
0
Comment
Question by:tommym121
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 450 total points
ID: 39703335
You can do that in quite a simple way using a #define, e.g.

#define StreamWarn log4cpp::Category::getRoot() << log4cpp::Priority::WARN 

//...

StreamWarm  << "This is my first PVLogger fatal Message";

Open in new window

0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 450 total points
ID: 39703343
BTW, you could implement the other message levels in a similar way:

#define StreamEmerg log4cpp::Category::getRoot() << log4cpp::Priority::EMERG 
#define StreamAlert log4cpp::Category::getRoot() << log4cpp::Priority::ALERT 
#define StreamError log4cpp::Category::getRoot() << log4cpp::Priority::ERROR 
#define StreamWarn log4cpp::Category::getRoot() << log4cpp::Priority::WARN 

Open in new window


or in a bit more general way

#define Stream(x) log4cpp::Category::getRoot() << log4cpp::Priority::X

// ...


Stream(WARN)  << "This is my first PVLogger fatal Message";

Stream(ALERT)  << "This is my first PVLogger fatal Message";

Open in new window

0
 
LVL 9

Assisted Solution

by:Subrat (C++ windows/Linux)
Subrat (C++ windows/Linux) earned 50 total points
ID: 39703881
A typo in jkr's comment
X should be x.

#define Stream(x) log4cpp::Category::getRoot() << log4cpp::Priority::x

The second option(bit more general...) is really a good approach.
0
 

Author Closing Comment

by:tommym121
ID: 39707535
Thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

831 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