Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

create a function to encapsulate log4cpp stream

Posted on 2013-12-07
4
Medium Priority
?
325 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
[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
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1800 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 1800 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 200 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

636 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