Solved

create a function to encapsulate log4cpp stream

Posted on 2013-12-07
4
299 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

738 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