Coverage Report

Created: 2025-07-29 14:50

/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
28.4k
#define LOG_INFO(...) ::doris::cloud::TaggableLogger(LOG(INFO), ##__VA_ARGS__)
34
351
#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
28.8k
    TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) {
65
28.8k
        if constexpr (sizeof...(args) == 0) {
66
1.89k
            stream_ << fmt;
67
1.89k
        } else {
68
1.89k
            stream_ << fmt::format(fmt, std::forward<Args>(args)...);
69
1.89k
        }
70
28.8k
        AnnotateTag::format_tag_list(stream_);
71
28.8k
    };
_ZN5doris5cloud14TaggableLoggerC2IJRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEERSoSt17basic_string_viewIcS6_EDpOT_
Line
Count
Source
64
313
    TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) {
65
313
        if constexpr (sizeof...(args) == 0) {
66
313
            stream_ << fmt;
67
313
        } else {
68
313
            stream_ << fmt::format(fmt, std::forward<Args>(args)...);
69
313
        }
70
313
        AnnotateTag::format_tag_list(stream_);
71
313
    };
_ZN5doris5cloud14TaggableLoggerC2IJEEERSoSt17basic_string_viewIcSt11char_traitsIcEEDpOT_
Line
Count
Source
64
26.9k
    TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) {
65
26.9k
        if constexpr (sizeof...(args) == 0) {
66
26.9k
            stream_ << fmt;
67
26.9k
        } else {
68
26.9k
            stream_ << fmt::format(fmt, std::forward<Args>(args)...);
69
26.9k
        }
70
26.9k
        AnnotateTag::format_tag_list(stream_);
71
26.9k
    };
_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_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_
Unexecuted instantiation: _ZN5doris5cloud14TaggableLoggerC2IJPKcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERSA_EEERSoSt17basic_string_viewIcS8_EDpOT_
Unexecuted instantiation: _ZN5doris5cloud14TaggableLoggerC2IJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiS9_S8_S9_EEERSoSt17basic_string_viewIcS6_EDpOT_
_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
167
    TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) {
65
167
        if constexpr (sizeof...(args) == 0) {
66
167
            stream_ << fmt;
67
167
        } else {
68
167
            stream_ << fmt::format(fmt, std::forward<Args>(args)...);
69
167
        }
70
167
        AnnotateTag::format_tag_list(stream_);
71
167
    };
_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
307
    TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) {
65
307
        if constexpr (sizeof...(args) == 0) {
66
307
            stream_ << fmt;
67
307
        } else {
68
307
            stream_ << fmt::format(fmt, std::forward<Args>(args)...);
69
307
        }
70
307
        AnnotateTag::format_tag_list(stream_);
71
307
    };
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
    };
_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
    };
_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
    };
_ZN5doris5cloud14TaggableLoggerC2IJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEERSoSt17basic_string_viewIcS6_EDpOT_
Line
Count
Source
64
10
    TaggableLogger(std::ostream& stream, std::string_view fmt, Args&&... args) : stream_(stream) {
65
10
        if constexpr (sizeof...(args) == 0) {
66
10
            stream_ << fmt;
67
10
        } else {
68
10
            stream_ << fmt::format(fmt, std::forward<Args>(args)...);
69
10
        }
70
10
        AnnotateTag::format_tag_list(stream_);
71
10
    };
72
73
    template <typename V>
74
128k
    TaggableLogger& tag(std::string_view key, const V& value) {
75
128k
        stream_ << ' ' << key << '=';
76
128k
        if constexpr (std::is_convertible_v<V, std::string_view>) {
77
58.4k
            stream_ << '"' << value << '"';
78
58.4k
        } else {
79
58.4k
            stream_ << value;
80
58.4k
        }
81
128k
        return *this;
82
128k
    }
_ZN5doris5cloud14TaggableLogger3tagINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERS1_St17basic_string_viewIcS6_ERKT_
Line
Count
Source
74
70.3k
    TaggableLogger& tag(std::string_view key, const V& value) {
75
70.3k
        stream_ << ' ' << key << '=';
76
70.3k
        if constexpr (std::is_convertible_v<V, std::string_view>) {
77
70.3k
            stream_ << '"' << value << '"';
78
70.3k
        } else {
79
70.3k
            stream_ << value;
80
70.3k
        }
81
70.3k
        return *this;
82
70.3k
    }
_ZN5doris5cloud14TaggableLogger3tagIlEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_
Line
Count
Source
74
35.5k
    TaggableLogger& tag(std::string_view key, const V& value) {
75
35.5k
        stream_ << ' ' << key << '=';
76
35.5k
        if constexpr (std::is_convertible_v<V, std::string_view>) {
77
35.5k
            stream_ << '"' << value << '"';
78
35.5k
        } else {
79
35.5k
            stream_ << value;
80
35.5k
        }
81
35.5k
        return *this;
82
35.5k
    }
_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
22.1k
    TaggableLogger& tag(std::string_view key, const V& value) {
75
22.1k
        stream_ << ' ' << key << '=';
76
22.1k
        if constexpr (std::is_convertible_v<V, std::string_view>) {
77
22.1k
            stream_ << '"' << value << '"';
78
22.1k
        } else {
79
22.1k
            stream_ << value;
80
22.1k
        }
81
22.1k
        return *this;
82
22.1k
    }
_ZN5doris5cloud14TaggableLogger3tagINS0_23RestoreJobCloudPB_StateEEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_
Line
Count
Source
74
8
    TaggableLogger& tag(std::string_view key, const V& value) {
75
8
        stream_ << ' ' << key << '=';
76
8
        if constexpr (std::is_convertible_v<V, std::string_view>) {
77
8
            stream_ << '"' << value << '"';
78
8
        } else {
79
8
            stream_ << value;
80
8
        }
81
8
        return *this;
82
8
    }
_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
    }
_ZN5doris5cloud14TaggableLogger3tagIjEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_
Line
Count
Source
74
1
    TaggableLogger& tag(std::string_view key, const V& value) {
75
1
        stream_ << ' ' << key << '=';
76
1
        if constexpr (std::is_convertible_v<V, std::string_view>) {
77
1
            stream_ << '"' << value << '"';
78
1
        } else {
79
1
            stream_ << value;
80
1
        }
81
1
        return *this;
82
1
    }
Unexecuted instantiation: _ZN5doris5cloud14TaggableLogger3tagINS0_12TxnErrorCodeEEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_
_ZN5doris5cloud14TaggableLogger3tagIiEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_
Line
Count
Source
74
272
    TaggableLogger& tag(std::string_view key, const V& value) {
75
272
        stream_ << ' ' << key << '=';
76
272
        if constexpr (std::is_convertible_v<V, std::string_view>) {
77
272
            stream_ << '"' << value << '"';
78
272
        } else {
79
272
            stream_ << value;
80
272
        }
81
272
        return *this;
82
272
    }
Unexecuted instantiation: _ZN5doris5cloud14TaggableLogger3tagIA33_cEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_
_ZN5doris5cloud14TaggableLogger3tagISt6atomicIlEEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_
Line
Count
Source
74
54
    TaggableLogger& tag(std::string_view key, const V& value) {
75
54
        stream_ << ' ' << key << '=';
76
54
        if constexpr (std::is_convertible_v<V, std::string_view>) {
77
54
            stream_ << '"' << value << '"';
78
54
        } else {
79
54
            stream_ << value;
80
54
        }
81
54
        return *this;
82
54
    }
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_
Unexecuted instantiation: _ZN5doris5cloud14TaggableLogger3tagINS0_18MultiVersionStatusEEERS1_St17basic_string_viewIcSt11char_traitsIcEERKT_
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
14
#define VLOG_DEBUG VLOG(DEBUG)