1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2010 Sage Weil <sage@newdream.net>
7 * Copyright (C) 2010 Dreamhost
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
19 #include <type_traits>
21 #include "global/global_context.h"
22 #include "common/config.h"
23 #include "common/likely.h"
24 #include "common/Clock.h"
27 extern void dout_emergency(const char * const str);
28 extern void dout_emergency(const std::string &str);
30 // intentionally conflict with endl
31 class _bad_endl_use_dendl_t { public: _bad_endl_use_dendl_t(int) {} };
32 static const _bad_endl_use_dendl_t endl = 0;
33 inline std::ostream& operator<<(std::ostream& out, _bad_endl_use_dendl_t) {
34 assert(0 && "you are using the wrong endl.. use std::endl or dendl");
38 class DoutPrefixProvider {
40 virtual string gen_prefix() const = 0;
41 virtual CephContext *get_cct() const = 0;
42 virtual unsigned get_subsys() const = 0;
43 virtual ~DoutPrefixProvider() {}
47 #define dout_prefix *_dout
49 #define dout_impl(cct, sub, v) \
51 if (cct->_conf->subsys.should_gather(sub, v)) { \
53 char __array[((v >= -1) && (v <= 200)) ? 0 : -1] __attribute__((unused)); \
55 static size_t _log_exp_length = 80; \
56 ceph::logging::Entry *_dout_e = cct->_log->create_entry(v, sub, &_log_exp_length); \
57 ostream _dout_os(&_dout_e->m_streambuf); \
58 static_assert(std::is_convertible<decltype(&*cct), \
59 CephContext* >::value, \
60 "provided cct must be compatible with CephContext*"); \
61 auto _dout_cct = cct; \
62 std::ostream* _dout = &_dout_os;
64 #define lsubdout(cct, sub, v) dout_impl(cct, ceph_subsys_##sub, v) dout_prefix
65 #define ldout(cct, v) dout_impl(cct, dout_subsys, v) dout_prefix
66 #define lderr(cct) dout_impl(cct, ceph_subsys_, -1) dout_prefix
68 #define ldpp_dout(dpp, v) if (dpp) dout_impl(dpp->get_cct(), dpp->get_subsys(), v) (*_dout << dpp->gen_prefix())
70 #define lgeneric_subdout(cct, sub, v) dout_impl(cct, ceph_subsys_##sub, v) *_dout
71 #define lgeneric_dout(cct, v) dout_impl(cct, ceph_subsys_, v) *_dout
72 #define lgeneric_derr(cct) dout_impl(cct, ceph_subsys_, -1) *_dout
74 #define ldlog_p1(cct, sub, lvl) \
75 (cct->_conf->subsys.should_gather((sub), (lvl)))
77 // NOTE: depend on magic value in _ASSERT_H so that we detect when
78 // /usr/include/assert.h clobbers our fancier version.
79 #define dendl_impl std::flush; \
80 _ASSERT_H->_log->submit_entry(_dout_e); \
84 #define dendl dendl_impl