]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/dout.h
add subtree-ish sources for 12.0.3
[ceph.git] / 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 "global/global_context.h"
20 #include "common/config.h"
21 #include "common/likely.h"
22 #include "common/Clock.h"
23 #include "log/Log.h"
24 #include "include/assert.h"
25
26 #include <iostream>
27 #include <pthread.h>
28 #include <streambuf>
29 #include <sstream>
30
31 extern void dout_emergency(const char * const str);
32 extern void dout_emergency(const std::string &str);
33
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");
39 return out;
40 }
41
42 class DoutPrefixProvider {
43 public:
44 virtual string gen_prefix() const = 0;
45 virtual CephContext *get_cct() const = 0;
46 virtual unsigned get_subsys() const = 0;
47 virtual ~DoutPrefixProvider() {}
48 };
49
50 // generic macros
51 #define dout_prefix *_dout
52
53 #define dout_impl(cct, sub, v) \
54 do { \
55 if (cct->_conf->subsys.should_gather(sub, v)) { \
56 if (0) { \
57 char __array[((v >= -1) && (v <= 200)) ? 0 : -1] __attribute__((unused)); \
58 } \
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;
64
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
68
69 #define ldpp_dout(dpp, v) if (dpp) dout_impl(dpp->get_cct(), dpp->get_subsys(), v) (*_dout << dpp->gen_prefix())
70
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
74
75 #define ldlog_p1(cct, sub, lvl) \
76 (cct->_conf->subsys.should_gather((sub), (lvl)))
77
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); \
82 } \
83 } while (0)
84
85 #define dendl dendl_impl
86
87 #endif