Commit Graph

2 Commits

Author SHA1 Message Date
Nadav Har'El
e88b7e3453 logging: conveniently log exception
This patch adds an output operator overload for std::exception_ptr, to
make it easy to log a caught exception. It always shows the exception's
exact type, and for some types of exceptions (subtypes of std::system_error
and std::exception) it prints more information.

For example, the code

  try {
    throw std::runtime_error("Hello world");
  } catch (...) {
    sstlog.warn("Exception: {}", std::current_exception());
  }

produces the output:
  Exception when deleting sstable file: std::runtime_error (Hello world)

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-06-30 11:23:01 +03:00
Avi Kivity
0362800e8d log: add slf4j-compatible logger class
Supports variadic logging with placeholders, e.g.

  logger.error("what happened? x = {}, y = {}", x, y);

Instantiate loggers as static thread_local, e.g.

  class foo {
      static thread_local logging::logger logger;
  };

  thread_local logging::logger foo::logger{logging::logger_for<foo>};
2014-12-29 17:09:41 +02:00