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 "global/global_context.h"
20 #include "common/config.h"
21 #include "common/likely.h"
22 #include "common/Clock.h"
24 #include "include/assert.h"
31 extern void dout_emergency(const char * const str
);
32 extern void dout_emergency(const std::string
&str
);
34 // intentionally conflict with endl
35 class _bad_endl_use_dendl_t
{ public: _bad_endl_use_dendl_t(int) {} };
36 static const _bad_endl_use_dendl_t endl
= 0;
37 inline std::ostream
& operator<<(std::ostream
& out
, _bad_endl_use_dendl_t
) {
38 assert(0 && "you are using the wrong endl.. use std::endl or dendl");
42 class DoutPrefixProvider
{
44 virtual string
gen_prefix() const = 0;
45 virtual CephContext
*get_cct() const = 0;
46 virtual unsigned get_subsys() const = 0;
47 virtual ~DoutPrefixProvider() {}
51 #define dout_prefix *_dout
53 #define dout_impl(cct, sub, v) \
55 if (cct->_conf->subsys.should_gather(sub, v)) { \
57 char __array[((v >= -1) && (v <= 200)) ? 0 : -1] __attribute__((unused)); \
59 static size_t _log_exp_length=80; \
60 ceph::logging::Entry *_dout_e = cct->_log->create_entry(v, sub, &_log_exp_length); \
61 ostream _dout_os(&_dout_e->m_streambuf); \
62 CephContext *_dout_cct = cct; \
63 std::ostream* _dout = &_dout_os;
65 #define lsubdout(cct, sub, v) dout_impl(cct, ceph_subsys_##sub, v) dout_prefix
66 #define ldout(cct, v) dout_impl(cct, dout_subsys, v) dout_prefix
67 #define lderr(cct) dout_impl(cct, ceph_subsys_, -1) dout_prefix
69 #define ldpp_dout(dpp, v) if (dpp) dout_impl(dpp->get_cct(), dpp->get_subsys(), v) (*_dout << dpp->gen_prefix())
71 #define lgeneric_subdout(cct, sub, v) dout_impl(cct, ceph_subsys_##sub, v) *_dout
72 #define lgeneric_dout(cct, v) dout_impl(cct, ceph_subsys_, v) *_dout
73 #define lgeneric_derr(cct) dout_impl(cct, ceph_subsys_, -1) *_dout
75 #define ldlog_p1(cct, sub, lvl) \
76 (cct->_conf->subsys.should_gather((sub), (lvl)))
78 // NOTE: depend on magic value in _ASSERT_H so that we detect when
79 // /usr/include/assert.h clobbers our fancier version.
80 #define dendl_impl std::flush; \
81 _ASSERT_H->_log->submit_entry(_dout_e); \
85 #define dendl dendl_impl