Commit Graph

18 Commits

Author SHA1 Message Date
Avi Kivity
926d340661 logger: be robust when exceptions are thrown while stringifying args
Instead of propagating the exception, swallow it and print it out in
the log message.

Fixes #672.
2015-12-21 19:58:08 +01:00
Amnon Heiman
521d9b62dd Add a level_name function to logger
This is a helper function that returns a log level name. It will be used
by the API to report the log levels.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-10-19 14:59:54 +03:00
Gleb Natapov
510ed4a1a0 Fix operator<< for std::exception_ptr to receive reference to an object 2015-10-15 17:14:50 +03:00
Gleb Natapov
d53be0a91e Move operator<< for std::exception_ptr to std namespace and make it get const
If the operator is not in std namespace it cannot be found in non global
contexts.
2015-09-27 14:16:35 +03:00
Avi Kivity
d5cf0fb2b1 Add license notices 2015-09-20 10:43:39 +03:00
Calle Wilund
be420f1108 Log: write logger name + message to stdout in same call
Fixes #319 - Interleaved logger names/messages from 1+ shards
(Does not do anything to guarantee atomicity of std::cout write itself though)
2015-09-09 12:29:55 +03:00
Asias He
eaa3fd299b logger: Align log level 2015-07-31 16:27:55 +08:00
Pekka Enberg
1626ec1986 log: Show log level when logging to stdout
Fixes #38.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-07-30 10:56:01 +02:00
Tomasz Grabiec
86735f93fa log: Prepend shard number and logger name 2015-07-28 11:31:08 +02:00
Asias He
744fa25852 logger: Fix compile error
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)

[1/6] CXX build/release/log.o
FAILED: g++ -MMD -MT build/release/log.o -MF build/release/log.o.d
-std=gnu++1y -g  -Wall -Werror -fvisibility=hidden -pthread -I.
-U_FORTIFY_SOURCE  -I/usr/include/jsoncpp/ -Wno-maybe-uninitialized
-DHAVE_XEN -DHAVE_HWLOC -DHAVE_NUMA -O2 -I build/release/gen -c -o
build/release/log.o log.cc
log.cc: In member function ‘void
logging::logger::really_do_log(logging::log_level, const char*,
logging::logger::stringer**, size_t)’:
log.cc:86:19: error: no match for ‘operator<<’ (operand types are
‘std::ostream {aka std::basic_ostream<char>}’ and ‘std::ostringstream
{aka std::basic_ostringstream<char>}’)
         std::cout << out;
                   ^
log.cc:86:19: note: candidate: operator<<(int, int) <built-in>
log.cc:86:19: note:   no known conversion for argument 2 from
‘std::ostringstream {aka std::basic_ostringstream<char>}’ to ‘int’
In file included from /usr/include/c++/5.1.1/iostream:39:0,
                 from core/sstring.hh:31,
                 from log.hh:8,
                 from log.cc:5:
2015-07-17 20:02:18 +02:00
Avi Kivity
91d8d46709 logger: support for syslog()
Note that while syslog() may block, we still call it synchronously via
the reactor thread.  Anything else would make logging a nightmare.
2015-07-15 16:20:37 +03:00
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