Commit Graph

25 Commits

Author SHA1 Message Date
Calle Wilund
443af44f24 log: Add output operator for std::exception&/std::system_error& 2016-04-18 13:51:15 +00:00
Paweł Dziepak
c1cffd0639 log: try to report logger failure
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2016-04-11 23:54:47 +01:00
Pekka Enberg
38a54df863 Fix pre-ScyllaDB copyright statements
People keep tripping over the old copyrights and copy-pasting them to
new files. Search and replace "Cloudius Systems" with "ScyllaDB".

Message-Id: <1460013664-25966-1-git-send-email-penberg@scylladb.com>
2016-04-08 08:12:47 +03:00
Tomasz Grabiec
838a038cbd log: Fix operator<<(std::ostream&, const std::exception_ptr&)
Attempt to print std::nested_exception currently results in exception
to leak outside the printer. Fix by capturing all exception in the
final catch block.

For nested exception, the logger will print now just
"std::nested_exception".  For nested exceptions specifically we should
log more, but that is a separate problem to solve.
Message-Id: <1457532215-7498-1-git-send-email-tgrabiec@scylladb.com>
2016-03-09 16:05:03 +02:00
Gleb Natapov
8dad399256 log: add space between log level and date in the outpu
It was dropped by 6dc51027a3

Message-Id: <20160306125313.GI2253@scylladb.com>
2016-03-07 13:06:06 +01:00
Takuya ASADA
6dc51027a3 log: make log.cc able to compile with g++-4.9
std::put_time() is not implemented on g++-4.9, so replace it with strftime().
Signed-off-by: Takuya ASADA <syuu@scylladb.com>
Message-Id: <1457024183-893-1-git-send-email-syuu@scylladb.com>
2016-03-04 12:48:43 +01:00
Tomasz Grabiec
9a5d7c6388 log: Prepend log lines with timestamp when printed to stdout
Useful for determining order of events in logs of different nodes, or
for estimating how much time passed between two events.

Fixes #941.

Example log:

INFO  2016-03-01 18:30:37,688 [shard 0] gossip - Waiting for gossip to settle before accepting client requests...
INFO  2016-03-01 18:30:45,689 [shard 0] gossip - No gossip backlog; proceeding
INFO  2016-03-01 18:30:45,689 [shard 0] storage_service - Starting listening for CQL clients on localhost:9042...

Message-Id: <1456853532-28800-1-git-send-email-tgrabiec@scylladb.com>
2016-03-02 13:49:39 +02:00
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