last updated 4.1.2007 dLog

About:
dLog is a std::stream based output logger that works with tags. For example:

dLog::write("fileOutput") << "open file:" << filename;

Download

dLog is available as source or binary (lib) package at sourceforge.

What is dLog

What it's not

More details
dLog is a simple to use and swift logger for c++. During many projects I encountered countless different implementations of the task to log files. Some of them where quite complex and some of them where as simple as writing to a file. Most of them lacked one or features I was looking for.
Ease of use combined with decent speed. This means a solution that can be turned on and off during runtime with close to zero cost when turned off.

Numbers

Most log systems are log level based. Numbers are fast to process but not very easy to remember. I have seen two different ways how numbers are used:

1. Assign a number to a bug/problem/issue/module of as system and when debugging just turn on that number. This works pretty well, but the number is hard to remember.

2. The number signifies amount of occurance. Everything that happens several times per second and is low level is level 1. Everything that happens seldom and is high level has a number of 9. Things in between gets the according number. In practice this approach results in huge output. You have to wade to an enormous number of detail information when debugging a certain issue. People then tend to abandon the system or write detail information temporarily into higher levels (and forget them in the end).

Strings

The dLog system uses string tags to identify an issue (quite similar to the number example 1.). For example to generate debug output for file output just define a tag and use it:

dLog::write("fileOutput") << "open file:" << filename;
// open file and do stuff ...
dLog::write("fileOutput") << "close file";

 

Another problem/issue uses a different tag. This is very easy to remember and can be optimized so the cost is negligible. Once a tag is defined in the system the tag can be retrieved compared against with little overhead. The table below shows the time required for operations:

  Operation
Ticks
Percent
  full processing of debug line
316992
100%
  disabled debug line (ignore)
6344
2%
  an unknown debug line (ignore)
10288
3.2%
  converting a string to upper case (for reference)
4952
1.5%
  executing no code between timestamps (for reference)
1288
0.4%

How to make it work in your project

dLog is based on std::streams. Therefore your project needs stl. Classes that you want to output to the stream need implement one friend function:

friend std::ostream &operator <<(std::ostream &o,const ClassName & class)
{
   o << "MyClass name:" << class.name << std::endl;
   return o;
}

The system contains one global log. This is realized through the singleton class Log. By default it opens a file called log.txt. To write to the log.txt file, just call the static functions from the Log class:

Log::SetTag("test",true);
Log::Write("TEST") << "test";
Log::Write("tEsT") << "more tests";

Note, that the tags are case insensitive. This helps to avoid stupid uppercase/lowercase errors!