Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / common / dout.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2004-2010 Sage Weil <sage@newdream.net>
7  * Copyright (C) 2010 Dreamhost
8  *
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.
13  *
14  */
15
16 #ifndef CEPH_DOUT_H
17 #define CEPH_DOUT_H
18
19 #include <type_traits>
20
21 #include "global/global_context.h"
22 #include "common/config.h"
23 #include "common/likely.h"
24 #include "common/Clock.h"
25 #include "log/Log.h"
26
27 extern void dout_emergency(const char * const str);
28 extern void dout_emergency(const std::string &str);
29
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");
35   return out;
36 }
37
38 class DoutPrefixProvider {
39 public:
40   virtual string gen_prefix() const = 0;
41   virtual CephContext *get_cct() const = 0;
42   virtual unsigned get_subsys() const = 0;
43   virtual ~DoutPrefixProvider() {}
44 };
45
46 // generic macros
47 #define dout_prefix *_dout
48
49 #define dout_impl(cct, sub, v)                                          \
50   do {                                                                  \
51   if (cct->_conf->subsys.should_gather(sub, v)) {                       \
52     if (0) {                                                            \
53       char __array[((v >= -1) && (v <= 200)) ? 0 : -1] __attribute__((unused)); \
54     }                                                                   \
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;
63
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
67
68 #define ldpp_dout(dpp, v) if (dpp) dout_impl(dpp->get_cct(), dpp->get_subsys(), v) (*_dout << dpp->gen_prefix())
69
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
73
74 #define ldlog_p1(cct, sub, lvl)                 \
75   (cct->_conf->subsys.should_gather((sub), (lvl)))
76
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);               \
81     }                                           \
82   } while (0)
83
84 #define dendl dendl_impl
85
86 #endif