31 #ifndef SCRIBO_CORE_LOGGER_HH
32 # define SCRIBO_CORE_LOGGER_HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/data/wrap.hh>
39 # include <mln/value/int_u8.hh>
40 # include <mln/debug/filename.hh>
41 # include <mln/io/pbm/save.hh>
42 # include <mln/io/pgm/save.hh>
43 # include <mln/io/ppm/save.hh>
44 # include <mln/util/timer.hh>
106 bool is_verbose()
const;
119 void set_verbose_prefix(
const std::string& prefix);
121 void log(
VerboseMode mode,
const std::string& text);
127 bool is_enabled()
const;
128 bool is_at_level(
Level level)
const;
130 void set_level(
Level level);
133 void set_filename_prefix(
const char *name);
136 template <
typename I>
137 void log_image(
Level dbg_level,
138 const Image<I>& ima,
const char *name);
150 void start_time_logging();
151 void stop_time_logging(
const std::string& time_title);
158 template <
typename V>
160 logger_& operator<<(std::ostream& (*f)(std::ostream&));
168 template <
unsigned n,
typename I>
170 const Image<I>& ima,
const char *name);
172 template <
unsigned n,
typename I>
175 const Image<I>& ima,
const char *name);
177 template <
typename I>
178 void log_image_dispatch(
const mln_value(I)&,
179 const Image<I>& ima,
const char *name);
181 template <
typename I>
183 const Image<I>& ima,
const char *name);
185 template <
typename I>
186 void log_image_dispatch(
const bool&,
187 const Image<I>& ima,
const char *name);
189 template <
typename I>
190 void log_image_rgb(
const I& ima,
const std::string& name);
192 template <
typename I>
193 void log_image_bool(
const I& ima,
const std::string& name);
195 template <
typename I>
196 void log_image_grayscale(
const I& ima,
const std::string& name);
203 std::string verbose_prefix_;
204 std::ostream& stream_;
206 std::stack<mln::util::timer> t_locals_;
219 # ifndef MLN_INCLUDE_ONLY
225 std::string to_upper(
const std::string& s)
228 for (
size_t i = 0; i < s.size(); ++i)
229 out[i] = toupper(s[i]);
246 default_verbose_mode_(Low),
247 verbose_prefix_(
"LOG: "),
254 logger_::logger_(
const logger_&)
264 mln_assertion(t_locals_.size() == 0);
271 return verbose_mode_ > Mute;
279 return mode == verbose_mode_;
289 default_verbose_mode_ = mode;
300 return default_verbose_mode_;
310 verbose_mode_ = mode;
321 return verbose_mode_;
329 verbose_prefix_ = prefix;
341 # ifndef SCRIBO_NDEBUG
342 if (verbose_mode_ < mode)
345 std::cerr << verbose_prefix_ << text << std::endl;
346 # endif // ! SCRIBO_NDEBUG
354 return level_ != None;
362 return level_ >=
level;
396 template <
typename I>
399 const Image<I>& ima,
const char *name)
406 # ifndef SCRIBO_NDEBUG
407 if (level_ < dbg_level)
410 std::cerr <<
"Logger - Saving image " << name << std::endl;
411 mln_assertion(
exact(ima).is_valid());
413 typedef mln_value(I) V;
414 log_image_dispatch(V(), ima, name);
415 # endif // ! SCRIBO_NDEBUG
424 t_locals_.top().restart();
432 mln_assertion(! t_locals_.empty());
434 t_locals_.top().stop();
435 if (verbose_mode_ >= Time)
436 std::cerr << time_title <<
" " << t_locals_.top() <<
"s" << std::endl;
443 template <
unsigned n,
typename I>
445 logger_::log_image_dispatch(
const value::int_u<n>&,
const Image<I>& ima,
const char *name)
447 log_image_grayscale(
exact(ima), name);
450 template <
unsigned n,
typename I>
452 logger_::log_image_dispatch(
const value::label<n>&,
const Image<I>& ima,
const char *name)
454 log_image_grayscale(
exact(ima), name);
458 template <
typename I>
460 logger_::log_image_dispatch(
const value::rgb8&,
const Image<I>& ima,
const char *name)
462 log_image_rgb(
exact(ima), name);
465 template <
typename I>
467 logger_::log_image_dispatch(
const bool&,
const Image<I>& ima,
const char *name)
469 log_image_bool(
exact(ima), name);
480 template <
typename I>
482 logger_::log_image_rgb(
const I& ima,
const std::string& name)
488 template <
typename I>
490 logger_::log_image_bool(
const I& ima,
const std::string& name)
496 template <
typename I>
498 logger_::log_image_grayscale(
const I& ima,
const std::string& name)
505 template <
typename V>
509 if (verbose_mode_ >= default_verbose_mode_)
519 if (verbose_mode_ >= default_verbose_mode_)
532 return scribo::debug::internal::logger_::instance();
544 static const mode_name mode[] = {
546 {
"USERDEBUG", UserDebug },
549 {
"MEDIUM", Medium },
551 {
"INVALID", Invalid }
555 std::string name_ = internal::to_upper(name);
556 for (i = 0; mode[i].mode != Invalid; ++i)
557 if (mode[i].name == name_)
563 # endif // ! MLN_INCLUDE_ONLY
569 #endif // ! SCRIBO_CORE_LOGGER_HH