Boost.Test > Components > The Unit Test Framework > Components > The Test Log

# The Test Log

#### Definition

defined in unit_test_log.hpp

##### Synopsis

    enum log_level {
        log_successful_tests     = 0,
        log_test_suites          = 1,
        log_messages             = 2,
        log_warnings             = 3,
        log_all_errors           = 4, // reported by unit test macros
        log_cpp_exception_errors = 5, // uncaught C++ exceptions
        log_system_errors        = 6, // including timeouts, signals, traps
        log_fatal_errors         = 7, // including unit test macros or
                                      // fatal system errors
        log_progress_only        = 8, // only unit test progress to be reported
        log_nothing              = 9
    };

    class unit_test_log
    {
        static unit_test_log& instance();
        void                  set_log_stream( std::ostream& str );
        void                  set_log_threshold_level( log_level lev );
        void                  set_log_format( std::string const& log_format );
        void                  set_log_formatter( unit_test_log_formatter* the_formatter );
    };

##### Description

To manage the testing output stream the Unit Test Framework uses a singleton class unit_test_log. This class is responsible for managing and formatting testing log. There two formats supported for testing log: human readable format and XML format. In most cases you do not need to use this class interface directly. The framework provides a simple way to set the log level and log format from outside of the test program. For more details and for the list of acceptable values see the Framework parameters.

- unit_test_log::set_log_stream(...)
  use this method to change the log output stream to the one specified by the str parameter. The default stream is std::cout. Note you need to be aware about lifetime of your log stream. It may have to extend beyond any initialization and test functions, unless you reset the log stream back to some other stream with longer lifetime before leaving the function scope. For example, you could use variable defined locally in test_main function, if you reset log stream back to std::cout at the function end.
- unit_test_log::set_log_threshold_level(...)
  use this method to set a log threshold level. Log record appears in output stream only if it's level exceed the threshold.
- unit_test_log::set_log_format(...)
  use this method to set the log format. For the list of acceptable values see log_format framework parameter.
- unit_test_log::set_log_formatter( ... )
  use this method to specify custom log formatter - instance of the class that implements unit_test_log_formatter interface

##### Construction

There is only one instance if this class automatically created by the framework at test startup. To access it use method unit_test_log::instance().