Project categories

Project site header
Category
Libraries
Platform
PC
Language
C++
Type
nCode project
Team members
1
Date
2009
State
Completed

Description

Tracer is a cross-platform library I developed for helping myself on log and debugging task with C++ programs. The library allows sending messages to a file or to a console (even if there is no console, the library will just open up one). It was built to switch easily between availbale output systems, or to add new ones. In addition, it supports many configurations (multithread control, display of file/function/line of code...).

The library has the following features

  • Built-in messages types: Info, Debug, Warning and Error.
  • Customizable messages types.
  • Possibility to print metadata (line number, file or function name).
  • Text color.
  • Redirection of output to file or console.
  • No performance degradation when disabled.
  • Uses C++ streams for text formating.
  • Suitable for multithread systems.

Images

No images available for this project.

Video

No video available for this project.

Code sample

The following code shows the classes for handling console output.

console.cpp (Write function)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
/*!
    \brief Displays a message on the console
 
    \param info Message information to output
*/
void CConsoleTracer::Write (const CMessageInfo &info)
{
#if defined (NCODE_TRACER_MULTITHREADED)
    CScopeLock lock (CConsoleTracer::console_mutex);
#endif
 
    std::string metadata ("");
 
    if (show_message_count)
    {
        metadata += MessageCount();
        metadata += "\t";
    }
 
    if (show_call_info_enabled)
    {
        metadata += info.call_file;
        metadata += " : ";
        metadata += info.call_function;
        metadata += " : ";
        std::ostringstream s;
        s << info.call_line;
        metadata += s.str();
        metadata += "\n";
    }
 
    std::string message (indentation_level, indentation_character);
 
    if (show_message_type)
    {
        message += info.type->GetName();
        message += ": ";
    }
 
    message += info.message;
 
 
    SetColor (info.type->MetadataForegroundColor(),
              info.type->MetadataBackgroundColor());
 
    std::cout << metadata;
 
    SetColor (info.type->MessageForegroundColor(),
              info.type->MessageBackgroundColor());
 
    std::cout << message << std::endl;
}
 
 

Links

Source code
Download the source code.
Documentation
Doxygen documentation of the library.

NOTE! This site uses cookies and similar technologies.

This site uses cookies and similar technologies. If you not change browser settings, you agree to it. Learn more

I understand