C++ logging

P

Paul Tremblay

Hi,

Is anyone aware of a good open-source logging library?. I have searched
on google but have not seen anything too useful (don't like log4cpp
because of lack of docs, by the time it takes me to figure out wahts
going on, I could have "rolled my own").

I just wanted to know if anyone could recommend any such library - to
prevent me having to re-invent the wheel?


Thanks
 
P

Phlip

Paul said:
Is anyone aware of a good open-source logging library?. I have searched
on google but have not seen anything too useful (don't like log4cpp
because of lack of docs, by the time it takes me to figure out wahts
going on, I could have "rolled my own").

I just wanted to know if anyone could recommend any such library - to
prevent me having to re-invent the wheel?

Such a library has so few technical challenges that maybe nobody bothered to
publish. Roll your own, use an std::eek:stream and correctly written
operator<<, and you'l be done in no time.
 
P

Panjandrum

Paul said:
Is anyone aware of a good open-source logging library?. I have searched
on google but have not seen anything too useful (don't like log4cpp
because of lack of docs, by the time it takes me to figure out wahts
going on, I could have "rolled my own").

I just wanted to know if anyone could recommend any such library - to
prevent me having to re-invent the wheel?

log4cxx: http://logging.apache.org/log4cxx/
Albeit you need to read the docs to understand it (if you are not
familiar with log4j).
 
P

Peter Julian

Paul Tremblay said:
Hi,

Is anyone aware of a good open-source logging library?. I have searched
on google but have not seen anything too useful (don't like log4cpp
because of lack of docs, by the time it takes me to figure out wahts
going on, I could have "rolled my own").

I just wanted to know if anyone could recommend any such library - to
prevent me having to re-invent the wheel?


Thanks

Why use a library when making you own log writer is fundamentally simple
(even with features)? Just wrap a Log class around a filename and
std::eek:fstream with a member function that writes a std::string or
std::eek:stream out to file.

void Log::logit(const std::string& r_s_)
{
....
}
 
J

Joseph Turian

Phlip said:
Such a library has so few technical challenges that maybe nobody bothered to
publish. Roll your own, use an std::eek:stream and correctly written
operator<<, and you'l be done in no time.

Actually, there are some technical challenges. Maybe you have some
insight into a solution to my troubles.

I have written a logging class that one uses as follows:

Debug::log(3) << "Log message at debuglevel 3\n";

Any time the Debug object is told to log something at a debuglevel that
is above the global debuglevel, it just ignores it. With me so far?

The problem is, I tend to have these sprinkled very liberally in my
code. In an inner-loop, there is a very high cost to converting the
object to strings, even if they are going to be not going to be output
because the debuglevel is too high.

The question is, is there a way to "short-circuit" this cost, if we
know that the text is not actually going to be output?


Joseph
 
V

Vyacheslav Kononenko

Joseph said:
Actually, there are some technical challenges. Maybe you have some
insight into a solution to my troubles.

I have written a logging class that one uses as follows:

Debug::log(3) << "Log message at debuglevel 3\n";

Any time the Debug object is told to log something at a debuglevel that
is above the global debuglevel, it just ignores it. With me so far?

The problem is, I tend to have these sprinkled very liberally in my
code. In an inner-loop, there is a very high cost to converting the
object to strings, even if they are going to be not going to be output
because the debuglevel is too high.

The question is, is there a way to "short-circuit" this cost, if we
know that the text is not actually going to be output?


Joseph

You can do something like this:

struct dummy {
template< class T >
dummy &operator<<( T ) {}
};

template< class Output >
class Logger {
Logger &operator<<( T t ) { out << t; }
private:
Output out;
};

#ifdef DEBUG
typedef Logger< std::eek:fstream > DebugLogger;
#else
typedef Logger< dummy > DebugLogger;
#endif

There are some questions that need consideration like how to create an
instance of out and Logger itself, but I hope the idea is clear.

Regards,
Vyacheslav
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top