Commit Graph

7 Commits

Author SHA1 Message Date
Avi Kivity
5b7e283451 logger: provide lexical_cast support for log_level
A boost bug prevents automatic generation, so help it.
2015-07-14 18:16:19 +03:00
Avi Kivity
5a5e411814 fix iostream 2015-07-14 18:15:52 +03:00
Avi Kivity
99a15de9e5 logger: de-thread_local-ize logger
The logger class constructor registers itself with the logger registry,
in order to enable dynamically setting log levels.  However, since
thread_local variables may be (and are) initialized at the time of first
use, when the program starts up no loggers are registered.

Fix by making loggers global, not thread_local.  This requires that the
registry use locking to prevent registration happening on different threads
from corrupting the registry.

Note that technically global variables can also be initialized at the
point of first use, and there is no portable way for classes to self-register.
However this is the best we can do.
2015-07-14 17:18:11 +03:00
Avi Kivity
a0cb90fe67 logger: add API to convert log_level to/from iostream 2015-07-14 15:33:02 +03:00
Avi Kivity
6ef552ef34 logger: add registry APIs to manage loggers 2015-07-14 15:19:14 +03:00
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