diff --git a/dlib/logger/logger_kernel_1.cpp b/dlib/logger/logger_kernel_1.cpp index 552124289..e867a1075 100644 --- a/dlib/logger/logger_kernel_1.cpp +++ b/dlib/logger/logger_kernel_1.cpp @@ -47,6 +47,21 @@ namespace dlib gd.set_level("",new_level); } + void set_all_logging_headers ( + const print_header_type& new_header + ) + { + logger::global_data& gd = logger::get_global_data(); + auto_mutex M(gd.m); + gd.loggers.reset(); + while (gd.loggers.move_next()) + { + gd.loggers.element()->print_header = new_header; + } + + gd.set_logger_header("",new_header); + } + // ---------------------------------------------------------------------------------------- namespace logger_helper_stuff @@ -300,7 +315,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- - logger::print_header_type logger::global_data:: + print_header_type logger::global_data:: logger_header ( const std::string& name ) diff --git a/dlib/logger/logger_kernel_1.h b/dlib/logger/logger_kernel_1.h index cd7d06050..25f6dfde1 100644 --- a/dlib/logger/logger_kernel_1.h +++ b/dlib/logger/logger_kernel_1.h @@ -70,6 +70,17 @@ namespace dlib const log_level& new_level ); + typedef void (*print_header_type)( + std::ostream& out, + const std::string& logger_name, + const log_level& l, + const uint64 thread_id + ); + + void set_all_logging_headers ( + const print_header_type& new_header + ); + // ---------------------------------------------------------------------------------------- void print_default_logger_header ( @@ -352,13 +363,6 @@ namespace dlib gd.set_output_hook(logger_name, hook); } - typedef void (*print_header_type)( - std::ostream& out, - const std::string& logger_name, - const log_level& l, - const uint64 thread_id - ); - print_header_type logger_header ( ) const { return print_header; } @@ -602,6 +606,10 @@ namespace dlib const log_level& new_level ); + friend void set_all_logging_headers ( + const print_header_type& new_header + ); + friend void set_all_logging_output_streams ( std::ostream& out ); diff --git a/dlib/logger/logger_kernel_abstract.h b/dlib/logger/logger_kernel_abstract.h index 2d09b042e..b6a4367a2 100644 --- a/dlib/logger/logger_kernel_abstract.h +++ b/dlib/logger/logger_kernel_abstract.h @@ -79,6 +79,26 @@ namespace dlib - std::bad_alloc !*/ +// ---------------------------------------------------------------------------------------- + + typedef void (*print_header_type)( + std::ostream& out, + const std::string& logger_name, + const log_level& l, + const uint64 thread_id + ); + + void set_all_logging_headers ( + const print_header_type& new_header + ); + /*! + ensures + - for all loggers L (even loggers not yet constructed): + - #L.logger_header() == new_header + throws + - std::bad_alloc + !*/ + // ---------------------------------------------------------------------------------------- template < @@ -361,13 +381,6 @@ namespace dlib - std::bad_alloc !*/ - typedef void (*print_header_type)( - std::ostream& out, - const std::string& logger_name, - const log_level& l, - const uint64 thread_id - ); - print_header_type logger_header ( ) const; /*!