/root/doris/cloud/src/common/logging.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <butil/containers/linked_list.h> |
21 | | #include <fmt/format.h> |
22 | | #include <glog/logging.h> |
23 | | |
24 | | #include <string_view> |
25 | | #include <type_traits> |
26 | | |
27 | | namespace doris::cloud { |
28 | | |
29 | | bool init_glog(const char* basename); |
30 | | |
31 | | /// Wrap a glog stream and tag on the log. usage: |
32 | | /// LOG_INFO("here is an info for a {} query", query_type).tag("query_id", queryId); |
33 | 8.53k | #define LOG_INFO(...) ::doris::cloud::TaggableLogger(LOG(INFO), ##__VA_ARGS__) |
34 | 25 | #define LOG_WARNING(...) ::doris::cloud::TaggableLogger(LOG(WARNING), ##__VA_ARGS__) |
35 | 0 | #define LOG_ERROR(...) ::doris::cloud::TaggableLogger(LOG(ERROR), ##__VA_ARGS__) |
36 | | #define LOG_FATAL(...) ::doris::cloud::TaggableLogger(LOG(FATAL), ##__VA_ARGS__) |
37 | | |
38 | | class AnnotateTag final : public butil::LinkNode<AnnotateTag> { |
39 | | struct default_tag_t {}; |
40 | | constexpr static default_tag_t default_tag {}; |
41 | | |
42 | | public: |
43 | | template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>, T>> |
44 | | AnnotateTag(std::string_view key, T value) |
45 | 12 | : AnnotateTag(default_tag, key, std::to_string(value)) {} _ZN5doris5cloud11AnnotateTagC2IccEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2IbbEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 3 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2IaaEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2IhhEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2IssEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2IttEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2IiiEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2IjjEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2IllEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
_ZN5doris5cloud11AnnotateTagC2ImmEESt17basic_string_viewIcSt11char_traitsIcEET_ Line | Count | Source | 45 | 1 | : AnnotateTag(default_tag, key, std::to_string(value)) {} |
|
46 | | AnnotateTag(std::string_view key, std::string_view value); |
47 | | ~AnnotateTag(); |
48 | | |
49 | | static void format_tag_list(std::ostream& stream); |
50 | | |
51 | | static void* operator new(size_t) = delete; |
52 | | static void* operator new[](size_t) = delete; |
53 | | |
54 | | private: |
55 | | explicit AnnotateTag(default_tag_t, std::string_view key, std::string value); |
56 | | |
57 | | std::string_view key_; |
58 | | std::string value_; |
59 | | }; |
60 | | |
61 | | class TaggableLogger { |
62 | | public: |
63 | | template <typename... Args> |
64 | 8.55k | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { |
65 | 8.55k | if constexpr (sizeof...(args) == 0) { |
66 | 1.81k | stream_ << fmt; |
67 | 1.81k | } else { |
68 | 1.81k | stream_ << fmt::format(fmt, std::forward<Args>(args)...); |
69 | 1.81k | } |
70 | 8.55k | AnnotateTag::format_tag_list(stream_); |
71 | 8.55k | }; _ZN5doris5cloud14TaggableLoggerC2IJEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_ Line | Count | Source | 64 | 6.74k | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 6.74k | if constexpr (sizeof...(args) == 0) { | 66 | 6.74k | stream_ << fmt; | 67 | 6.74k | } else { | 68 | 6.74k | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 6.74k | } | 70 | 6.74k | AnnotateTag::format_tag_list(stream_); | 71 | 6.74k | }; |
_ZN5doris5cloud14TaggableLoggerC2IJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_lRlRKS8_EEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 1 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 1 | if constexpr (sizeof...(args) == 0) { | 66 | 1 | stream_ << fmt; | 67 | 1 | } else { | 68 | 1 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 1 | } | 70 | 1 | AnnotateTag::format_tag_list(stream_); | 71 | 1 | }; |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLoggerC2IJRSt17basic_string_viewIcSt11char_traitsIcEEEEERSoS6_DpOT_ _ZN5doris5cloud14TaggableLoggerC2IJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKS8_S8_EEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 50 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 50 | if constexpr (sizeof...(args) == 0) { | 66 | 50 | stream_ << fmt; | 67 | 50 | } else { | 68 | 50 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 50 | } | 70 | 50 | AnnotateTag::format_tag_list(stream_); | 71 | 50 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 296 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 296 | if constexpr (sizeof...(args) == 0) { | 66 | 296 | stream_ << fmt; | 67 | 296 | } else { | 68 | 296 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 296 | } | 70 | 296 | AnnotateTag::format_tag_list(stream_); | 71 | 296 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_S8_EEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 2 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 2 | if constexpr (sizeof...(args) == 0) { | 66 | 2 | stream_ << fmt; | 67 | 2 | } else { | 68 | 2 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 2 | } | 70 | 2 | AnnotateTag::format_tag_list(stream_); | 71 | 2 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 1 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 1 | if constexpr (sizeof...(args) == 0) { | 66 | 1 | stream_ << fmt; | 67 | 1 | } else { | 68 | 1 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 1 | } | 70 | 1 | AnnotateTag::format_tag_list(stream_); | 71 | 1 | }; |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLoggerC2IJRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_SA_EEERSoSt17basic_string_viewIcS6_EDpOT_ Unexecuted instantiation: _ZN5doris5cloud14TaggableLoggerC2IJiRiEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_ _ZN5doris5cloud14TaggableLoggerC2IJRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEilEEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 2 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 2 | if constexpr (sizeof...(args) == 0) { | 66 | 2 | stream_ << fmt; | 67 | 2 | } else { | 68 | 2 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 2 | } | 70 | 2 | AnnotateTag::format_tag_list(stream_); | 71 | 2 | }; |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLoggerC2IJRiEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_ _ZN5doris5cloud14TaggableLoggerC2IJRNS0_12TxnErrorCodeEEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_ Line | Count | Source | 64 | 1 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 1 | if constexpr (sizeof...(args) == 0) { | 66 | 1 | stream_ << fmt; | 67 | 1 | } else { | 68 | 1 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 1 | } | 70 | 1 | AnnotateTag::format_tag_list(stream_); | 71 | 1 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJRlEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_ Line | Count | Source | 64 | 138 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 138 | if constexpr (sizeof...(args) == 0) { | 66 | 138 | stream_ << fmt; | 67 | 138 | } else { | 68 | 138 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 138 | } | 70 | 138 | AnnotateTag::format_tag_list(stream_); | 71 | 138 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 6 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 6 | if constexpr (sizeof...(args) == 0) { | 66 | 6 | stream_ << fmt; | 67 | 6 | } else { | 68 | 6 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 6 | } | 70 | 6 | AnnotateTag::format_tag_list(stream_); | 71 | 6 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJRfEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_ Line | Count | Source | 64 | 283 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 283 | if constexpr (sizeof...(args) == 0) { | 66 | 283 | stream_ << fmt; | 67 | 283 | } else { | 68 | 283 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 283 | } | 70 | 283 | AnnotateTag::format_tag_list(stream_); | 71 | 283 | }; |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLoggerC2IJRSt17basic_string_viewIcSt11char_traitsIcEEbEEERSoS6_DpOT_ _ZN5doris5cloud14TaggableLoggerC2IJRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_RKlRS8_EEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 5 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 5 | if constexpr (sizeof...(args) == 0) { | 66 | 5 | stream_ << fmt; | 67 | 5 | } else { | 68 | 5 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 5 | } | 70 | 5 | AnnotateTag::format_tag_list(stream_); | 71 | 5 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJmRmEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_ Line | Count | Source | 64 | 5 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 5 | if constexpr (sizeof...(args) == 0) { | 66 | 5 | stream_ << fmt; | 67 | 5 | } else { | 68 | 5 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 5 | } | 70 | 5 | AnnotateTag::format_tag_list(stream_); | 71 | 5 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJmRmlEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_ Line | Count | Source | 64 | 5 | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 5 | if constexpr (sizeof...(args) == 0) { | 66 | 5 | stream_ << fmt; | 67 | 5 | } else { | 68 | 5 | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 5 | } | 70 | 5 | AnnotateTag::format_tag_list(stream_); | 71 | 5 | }; |
_ZN5doris5cloud14TaggableLoggerC2IJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_EEERSoSt17basic_string_viewIcS6_EDpOT_ Line | Count | Source | 64 | 1.02k | TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) { | 65 | 1.02k | if constexpr (sizeof...(args) == 0) { | 66 | 1.02k | stream_ << fmt; | 67 | 1.02k | } else { | 68 | 1.02k | stream_ << fmt::format(fmt, std::forward<Args>(args)...); | 69 | 1.02k | } | 70 | 1.02k | AnnotateTag::format_tag_list(stream_); | 71 | 1.02k | }; |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLoggerC2IJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiS9_S8_S9_EEERSoSt17basic_string_viewIcS6_EDpOT_ |
72 | | |
73 | | template <typename V> |
74 | 16.9k | TaggableLogger& tag(std::string_view key, const V& value) { |
75 | 16.9k | stream_ << ' ' << key << '='; |
76 | 16.9k | if constexpr (std::is_convertible_v<V, std::string_view>) { |
77 | 6.87k | stream_ << '"' << value << '"'; |
78 | 6.87k | } else { |
79 | 6.87k | stream_ << value; |
80 | 6.87k | } |
81 | 16.9k | return *this; |
82 | 16.9k | } _ZN5doris5cloud14TaggableLogger3tagINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERS1_St17basic_string_viewIcS6_ERKT_ Line | Count | Source | 74 | 10.0k | TaggableLogger& tag(std::string_view key, const V& value) { | 75 | 10.0k | stream_ << ' ' << key << '='; | 76 | 10.0k | if constexpr (std::is_convertible_v<V, std::string_view>) { | 77 | 10.0k | stream_ << '"' << value << '"'; | 78 | 10.0k | } else { | 79 | 10.0k | stream_ << value; | 80 | 10.0k | } | 81 | 10.0k | return *this; | 82 | 10.0k | } |
_ZN5doris5cloud14TaggableLogger3tagIPKcEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ Line | Count | Source | 74 | 3 | TaggableLogger& tag(std::string_view key, const V& value) { | 75 | 3 | stream_ << ' ' << key << '='; | 76 | 3 | if constexpr (std::is_convertible_v<V, std::string_view>) { | 77 | 3 | stream_ << '"' << value << '"'; | 78 | 3 | } else { | 79 | 3 | stream_ << value; | 80 | 3 | } | 81 | 3 | return *this; | 82 | 3 | } |
_ZN5doris5cloud14TaggableLogger3tagImEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ Line | Count | Source | 74 | 2.11k | TaggableLogger& tag(std::string_view key, const V& value) { | 75 | 2.11k | stream_ << ' ' << key << '='; | 76 | 2.11k | if constexpr (std::is_convertible_v<V, std::string_view>) { | 77 | 2.11k | stream_ << '"' << value << '"'; | 78 | 2.11k | } else { | 79 | 2.11k | stream_ << value; | 80 | 2.11k | } | 81 | 2.11k | return *this; | 82 | 2.11k | } |
_ZN5doris5cloud14TaggableLogger3tagIlEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ Line | Count | Source | 74 | 4.09k | TaggableLogger& tag(std::string_view key, const V& value) { | 75 | 4.09k | stream_ << ' ' << key << '='; | 76 | 4.09k | if constexpr (std::is_convertible_v<V, std::string_view>) { | 77 | 4.09k | stream_ << '"' << value << '"'; | 78 | 4.09k | } else { | 79 | 4.09k | stream_ << value; | 80 | 4.09k | } | 81 | 4.09k | return *this; | 82 | 4.09k | } |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLogger3tagINS0_12TxnErrorCodeEEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ _ZN5doris5cloud14TaggableLogger3tagIiEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ Line | Count | Source | 74 | 252 | TaggableLogger& tag(std::string_view key, const V& value) { | 75 | 252 | stream_ << ' ' << key << '='; | 76 | 252 | if constexpr (std::is_convertible_v<V, std::string_view>) { | 77 | 252 | stream_ << '"' << value << '"'; | 78 | 252 | } else { | 79 | 252 | stream_ << value; | 80 | 252 | } | 81 | 252 | return *this; | 82 | 252 | } |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLogger3tagIA33_cEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ _ZN5doris5cloud14TaggableLogger3tagINS0_15MetaServiceCodeEEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ Line | Count | Source | 74 | 370 | TaggableLogger& tag(std::string_view key, const V& value) { | 75 | 370 | stream_ << ' ' << key << '='; | 76 | 370 | if constexpr (std::is_convertible_v<V, std::string_view>) { | 77 | 370 | stream_ << '"' << value << '"'; | 78 | 370 | } else { | 79 | 370 | stream_ << value; | 80 | 370 | } | 81 | 370 | return *this; | 82 | 370 | } |
_ZN5doris5cloud14TaggableLogger3tagISt6atomicIlEEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ Line | Count | Source | 74 | 50 | TaggableLogger& tag(std::string_view key, const V& value) { | 75 | 50 | stream_ << ' ' << key << '='; | 76 | 50 | if constexpr (std::is_convertible_v<V, std::string_view>) { | 77 | 50 | stream_ << '"' << value << '"'; | 78 | 50 | } else { | 79 | 50 | stream_ << value; | 80 | 50 | } | 81 | 50 | return *this; | 82 | 50 | } |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLogger3tagIA21_cEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ _ZN5doris5cloud14TaggableLogger3tagIbEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_ Line | Count | Source | 74 | 3 | TaggableLogger& tag(std::string_view key, const V& value) { | 75 | 3 | stream_ << ' ' << key << '='; | 76 | 3 | if constexpr (std::is_convertible_v<V, std::string_view>) { | 77 | 3 | stream_ << '"' << value << '"'; | 78 | 3 | } else { | 79 | 3 | stream_ << value; | 80 | 3 | } | 81 | 3 | return *this; | 82 | 3 | } |
Unexecuted instantiation: _ZN5doris5cloud14TaggableLogger3tagISt17basic_string_viewIcSt11char_traitsIcEEEERS1_S6_RKT_ |
83 | | |
84 | | private: |
85 | | std::ostream& stream_; |
86 | | }; |
87 | | |
88 | | } // namespace doris::cloud |
89 | | |
90 | | // To keep it simple and practical, we don't actually need so many VLOG levels. |
91 | | // Using `VLOG(${number})` is confusing and hard to desid in most cases, all we |
92 | | // need is a complementary debug level to glog's default 4 levels of logging. |
93 | | // "One VLOG level to rule them all!" |
94 | | #define DEBUG 5 |
95 | | // VLOG_DEBUG is alias of VLOG(DEBUG) I.O.W VLOG(5) |
96 | 7 | #define VLOG_DEBUG VLOG(DEBUG) |