473,413 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

C++ logging

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

Jul 23 '05 #1
5 3122
Paul Tremblay wrote:
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::ostream and correctly written
operator<<, and you'l be done in no time.

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #2
Paul Tremblay wrote:
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).

Jul 23 '05 #3

"Paul Tremblay" <pt*******@hotmail.com> wrote in message
news:d8**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
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::ofstream with a member function that writes a std::string or
std::ostream out to file.

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

Jul 23 '05 #4


Phlip wrote:
Such a library has so few technical challenges that maybe nobody bothered to
publish. Roll your own, use an std::ostream 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

Jul 23 '05 #5


Joseph Turian wrote:
Phlip wrote:
Such a library has so few technical challenges that maybe nobody bothered to
publish. Roll your own, use an std::ostream 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


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::ofstream > 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

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jjesso | last post by:
I am trying to add a new logging level. logging.config.fileConfig("bengineLog.cfg") logging.CLIENT = logging.INFO + 1 logging.addLevelName( logging.CLIENT, 'CLIENT' ) logging.root.setLevel( )...
0
by: Karuppasamy | last post by:
H I am trying to use the Logging Module provided by Microsoft Application Blocks for .Net I installed everything as per the Instructions given in the 'Development Using the Logging Block' ...
6
by: pmatos | last post by:
Hi all, I am trying to create a simple but efficient C++ logging class. I know there are lots of them out there but I want something simple and efficient. The number one requirement is the...
23
by: Rotem | last post by:
Hi, while working on something in my current project I have made several improvements to the logging package in Python, two of them are worth mentioning: 1. addition of a logging record field...
6
by: Burkhard Schultheis | last post by:
As I wrote last week, we have a problem with a DB2 V8 on Linux. Here is what is in db2diag.log during online backup: Starting a full database backup. 2004-04-01-02.33.54.760164 ...
0
by: robert | last post by:
As more and more python packages are starting to use the bloomy (Java-ish) 'logging' module in a mood of responsibility and as I am not overly happy with the current "thickener" style of usage, I...
0
by: rajesh.hanchate | last post by:
Please help me in resolving this issue. I am using EnterpriseLibrary 2.0 Exception and logging block for logging exceptions to event log. It works fine for sometime. After some time it stops...
3
by: Chris Shenton | last post by:
I am setting up handlers to log DEBUG and above to a rotating file and ERROR and above to console. But if any of my code calls a logger (e.g., logging.error("foo")) before I setup my handlers, the...
3
by: Lowell Alleman | last post by:
Here is the situation: I wrote my own log handler class (derived from logging.Handler) and I want to be able to use it from a logging config file, that is, a config file loaded with the...
4
by: samwyse | last post by:
In the Python 2.5 Library Reference, section 14.5.3 (Logging to multiple destinations), an example is given of logging to both a file and the console. This is done by using logging.basicConfig()...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.