Coverage Report

Created: 2025-06-07 16:22

/root/doris/be/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 <memory>
21
22
// GLOG defines this based on the system but doesn't check if it's already
23
// been defined.  undef it first to avoid warnings.
24
// glog MUST be included before gflags.  Instead of including them,
25
// our files should include this file instead.
26
#undef _XOPEN_SOURCE
27
// This is including a glog internal file.  We want this to expose the
28
// function to get the stack trace.
29
#include <glog/logging.h> // IWYU pragma: export
30
#undef MutexLock
31
32
// Define VLOG levels.  We want display per-row info less than per-file which
33
// is less than per-query.  For now per-connection is the same as per-query.
34
#define VLOG_CONNECTION VLOG(1)
35
18.4E
#define VLOG_RPC VLOG(8)
36
18.4E
#define VLOG_QUERY VLOG(1)
37
18.4E
#define VLOG_FILE VLOG(2)
38
18.4E
#define VLOG_ROW VLOG(10)
39
18.4E
#define VLOG_PROGRESS VLOG(2)
40
6.64M
#define VLOG_TRACE VLOG(10)
41
18.4E
#define VLOG_DEBUG VLOG(7)
42
74.5k
#define VLOG_NOTICE VLOG(3)
43
18.4E
#define VLOG_CRITICAL VLOG(1)
44
45
#define VLOG_CONNECTION_IS_ON VLOG_IS_ON(1)
46
#define VLOG_RPC_IS_ON VLOG_IS_ON(8)
47
#define VLOG_QUERY_IS_ON VLOG_IS_ON(1)
48
4.19k
#define VLOG_FILE_IS_ON VLOG_IS_ON(2)
49
#define VLOG_ROW_IS_ON VLOG_IS_ON(10)
50
4.22M
#define VLOG_TRACE_IS_ON VLOG_IS_ON(10)
51
599k
#define VLOG_DEBUG_IS_ON VLOG_IS_ON(7)
52
2.43k
#define VLOG_NOTICE_IS_ON VLOG_IS_ON(3)
53
0
#define VLOG_CRITICAL_IS_ON VLOG_IS_ON(1)
54
55
/// Define a wrapper around DCHECK for strongly typed enums that print a useful error
56
/// message on failure.
57
#define DCHECK_ENUM_EQ(a, b)                                                 \
58
    DCHECK(a == b) << "[ " #a " = " << static_cast<int>(a) << " , " #b " = " \
59
                   << static_cast<int>(b) << " ]"
60
61
#include <fmt/format.h>
62
63
#include "util/uid_util.h"
64
65
namespace doris {
66
67
// glog doesn't allow multiple invocations of InitGoogleLogging. This method conditionally
68
// calls InitGoogleLogging only if it hasn't been called before.
69
bool init_glog(const char* basename);
70
71
// Shuts down the google logging library. Call before exit to ensure that log files are
72
// flushed. May only be called once.
73
void shutdown_logging();
74
75
void update_logging(const std::string& name, const std::string& value);
76
77
class TaggableLogger {
78
public:
79
    TaggableLogger(const char* file, int line, google::LogSeverity severity)
80
969k
            : _msg(file, line, severity) {}
81
82
    template <typename... Args>
83
969k
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
969k
        if constexpr (sizeof...(args) == 0) {
85
15.3k
            _msg.stream() << fmt;
86
15.3k
        } else {
87
15.3k
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
15.3k
        }
89
969k
        return *this;
90
969k
    }
_ZN5doris14TaggableLoggerclIJEEERS0_RKSt17basic_string_viewIcSt11char_traitsIcEEDpOT_
Line
Count
Source
83
954k
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
954k
        if constexpr (sizeof...(args) == 0) {
85
954k
            _msg.stream() << fmt;
86
954k
        } else {
87
954k
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
954k
        }
89
954k
        return *this;
90
954k
    }
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_S7_S7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRlS2_S2_EEERS0_RKSt17basic_string_viewIcSt11char_traitsIcEEDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmEEERS0_RKSt17basic_string_viewIcS5_EDpOT_
_ZN5doris14TaggableLoggerclIJRSt17basic_string_viewIcSt11char_traitsIcEEEEERS0_RKS5_DpOT_
Line
Count
Source
83
8.54k
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
8.54k
        if constexpr (sizeof...(args) == 0) {
85
8.54k
            _msg.stream() << fmt;
86
8.54k
        } else {
87
8.54k
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
8.54k
        }
89
8.54k
        return *this;
90
8.54k
    }
_ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Line
Count
Source
83
55
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
55
        if constexpr (sizeof...(args) == 0) {
85
55
            _msg.stream() << fmt;
86
55
        } else {
87
55
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
55
        }
89
55
        return *this;
90
55
    }
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRlEEERS0_RKSt17basic_string_viewIcSt11char_traitsIcEEDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRlS2_S2_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEERS0_RKSt17basic_string_viewIcS6_EDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRlNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES2_S8_EEERS0_RKSt17basic_string_viewIcS6_EDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRlNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEERS0_RKSt17basic_string_viewIcS6_EDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJPKcEEERS0_RKSt17basic_string_viewIcSt11char_traitsIcEEDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKcEEERS0_RKSt17basic_string_viewIcS5_EDpOT_
_ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Line
Count
Source
83
1.64k
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
1.64k
        if constexpr (sizeof...(args) == 0) {
85
1.64k
            _msg.stream() << fmt;
86
1.64k
        } else {
87
1.64k
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
1.64k
        }
89
1.64k
        return *this;
90
1.64k
    }
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEKS7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERiS7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
_ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_S7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Line
Count
Source
83
2.99k
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
2.99k
        if constexpr (sizeof...(args) == 0) {
85
2.99k
            _msg.stream() << fmt;
86
2.99k
        } else {
87
2.99k
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
2.99k
        }
89
2.99k
        return *this;
90
2.99k
    }
_ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_25PPlanFragmentCancelReasonERKS7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Line
Count
Source
83
7
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
7
        if constexpr (sizeof...(args) == 0) {
85
7
            _msg.stream() << fmt;
86
7
        } else {
87
7
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
7
        }
89
7
        return *this;
90
7
    }
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKcEEERS0_RKSt17basic_string_viewIcS5_EDpOT_
_ZN5doris14TaggableLoggerclIJmNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERdEEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Line
Count
Source
83
110
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
110
        if constexpr (sizeof...(args) == 0) {
85
110
            _msg.stream() << fmt;
86
110
        } else {
87
110
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
110
        }
89
110
        return *this;
90
110
    }
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERmS7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
_ZN5doris14TaggableLoggerclIJRlS2_S2_RmEEERS0_RKSt17basic_string_viewIcSt11char_traitsIcEEDpOT_
Line
Count
Source
83
178
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
178
        if constexpr (sizeof...(args) == 0) {
85
178
            _msg.stream() << fmt;
86
178
        } else {
87
178
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
178
        }
89
178
        return *this;
90
178
    }
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERiS8_S9_RjRlSB_SB_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERjRlS9_S9_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
_ZN5doris14TaggableLoggerclIJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERiRlSA_lRjSA_SA_SA_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Line
Count
Source
83
178
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
178
        if constexpr (sizeof...(args) == 0) {
85
178
            _msg.stream() << fmt;
86
178
        } else {
87
178
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
178
        }
89
178
        return *this;
90
178
    }
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJRlS2_S2_RNS_6StatusEEEERS0_RKSt17basic_string_viewIcSt11char_traitsIcEEDpOT_
_ZN5doris14TaggableLoggerclIJRlS2_S2_S2_RKmEEERS0_RKSt17basic_string_viewIcSt11char_traitsIcEEDpOT_
Line
Count
Source
83
178
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
178
        if constexpr (sizeof...(args) == 0) {
85
178
            _msg.stream() << fmt;
86
178
        } else {
87
178
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
178
        }
89
178
        return *this;
90
178
    }
Unexecuted instantiation: _ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERiS7_S7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
_ZN5doris14TaggableLoggerclIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERiS7_EEERS0_RKSt17basic_string_viewIcS5_EDpOT_
Line
Count
Source
83
1.47k
    TaggableLogger& operator()(const std::string_view& fmt, Args&&... args) {
84
1.47k
        if constexpr (sizeof...(args) == 0) {
85
1.47k
            _msg.stream() << fmt;
86
1.47k
        } else {
87
1.47k
            _msg.stream() << fmt::format(fmt, std::forward<Args&&>(args)...);
88
1.47k
        }
89
1.47k
        return *this;
90
1.47k
    }
91
92
    template <typename V>
93
2.32M
    TaggableLogger& tag(std::string_view key, V&& value) {
94
2.32M
        _msg.stream() << '|' << key << '=';
95
2.32M
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
2.32M
            _msg.stream() << print_id(value);
97
2.32M
        } else {
98
2.32M
            _msg.stream() << value;
99
2.32M
        }
100
2.32M
        return *this;
101
2.32M
    }
_ZN5doris14TaggableLogger3tagIRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERS0_St17basic_string_viewIcS5_EOT_
Line
Count
Source
93
4.46k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
4.46k
        _msg.stream() << '|' << key << '=';
95
4.46k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
4.46k
            _msg.stream() << print_id(value);
97
4.46k
        } else {
98
4.46k
            _msg.stream() << value;
99
4.46k
        }
100
4.46k
        return *this;
101
4.46k
    }
_ZN5doris14TaggableLogger3tagIRKiEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Line
Count
Source
93
2.99k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
2.99k
        _msg.stream() << '|' << key << '=';
95
2.99k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
2.99k
            _msg.stream() << print_id(value);
97
2.99k
        } else {
98
2.99k
            _msg.stream() << value;
99
2.99k
        }
100
2.99k
        return *this;
101
2.99k
    }
_ZN5doris14TaggableLogger3tagIRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERS0_St17basic_string_viewIcS5_EOT_
Line
Count
Source
93
372k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
372k
        _msg.stream() << '|' << key << '=';
95
372k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
372k
            _msg.stream() << print_id(value);
97
372k
        } else {
98
372k
            _msg.stream() << value;
99
372k
        }
100
372k
        return *this;
101
372k
    }
_ZN5doris14TaggableLogger3tagIRlEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Line
Count
Source
93
388k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
388k
        _msg.stream() << '|' << key << '=';
95
388k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
388k
            _msg.stream() << print_id(value);
97
388k
        } else {
98
388k
            _msg.stream() << value;
99
388k
        }
100
388k
        return *this;
101
388k
    }
Unexecuted instantiation: _ZN5doris14TaggableLogger3tagIRKNS_9TTaskType4typeEEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
_ZN5doris14TaggableLogger3tagIRKlEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Line
Count
Source
93
805k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
805k
        _msg.stream() << '|' << key << '=';
95
805k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
805k
            _msg.stream() << print_id(value);
97
805k
        } else {
98
805k
            _msg.stream() << value;
99
805k
        }
100
805k
        return *this;
101
805k
    }
_ZN5doris14TaggableLogger3tagIRjEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Line
Count
Source
93
22.5k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
22.5k
        _msg.stream() << '|' << key << '=';
95
22.5k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
22.5k
            _msg.stream() << print_id(value);
97
22.5k
        } else {
98
22.5k
            _msg.stream() << value;
99
22.5k
        }
100
22.5k
        return *this;
101
22.5k
    }
_ZN5doris14TaggableLogger3tagINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERS0_St17basic_string_viewIcS5_EOT_
Line
Count
Source
93
235k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
235k
        _msg.stream() << '|' << key << '=';
95
235k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
235k
            _msg.stream() << print_id(value);
97
235k
        } else {
98
235k
            _msg.stream() << value;
99
235k
        }
100
235k
        return *this;
101
235k
    }
_ZN5doris14TaggableLogger3tagIRKNS_9TPushType4typeEEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Line
Count
Source
93
1.53k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
1.53k
        _msg.stream() << '|' << key << '=';
95
1.53k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
1.53k
            _msg.stream() << print_id(value);
97
1.53k
        } else {
98
1.53k
            _msg.stream() << value;
99
1.53k
        }
100
1.53k
        return *this;
101
1.53k
    }
_ZN5doris14TaggableLogger3tagImEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Line
Count
Source
93
255k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
255k
        _msg.stream() << '|' << key << '=';
95
255k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
255k
            _msg.stream() << print_id(value);
97
255k
        } else {
98
255k
            _msg.stream() << value;
99
255k
        }
100
255k
        return *this;
101
255k
    }
_ZN5doris14TaggableLogger3tagIlEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Line
Count
Source
93
3.32k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
3.32k
        _msg.stream() << '|' << key << '=';
95
3.32k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
3.32k
            _msg.stream() << print_id(value);
97
3.32k
        } else {
98
3.32k
            _msg.stream() << value;
99
3.32k
        }
100
3.32k
        return *this;
101
3.32k
    }
Unexecuted instantiation: _ZN5doris14TaggableLogger3tagIRbEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Unexecuted instantiation: _ZN5doris14TaggableLogger3tagIRKSt6vectorINS_7VersionESaIS3_EEEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
_ZN5doris14TaggableLogger3tagIRiEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
Line
Count
Source
93
229k
    TaggableLogger& tag(std::string_view key, V&& value) {
94
229k
        _msg.stream() << '|' << key << '=';
95
229k
        if constexpr (std::is_same_v<V, TUniqueId> || std::is_same_v<V, PUniqueId>) {
96
229k
            _msg.stream() << print_id(value);
97
229k
        } else {
98
229k
            _msg.stream() << value;
99
229k
        }
100
229k
        return *this;
101
229k
    }
Unexecuted instantiation: _ZN5doris14TaggableLogger3tagIRKNS_17TAgentTaskRequestEEERS0_St17basic_string_viewIcSt11char_traitsIcEEOT_
102
103
    template <typename E>
104
1.53k
    TaggableLogger& error(E&& error) {
105
1.53k
        _msg.stream() << "|error=" << error;
106
1.53k
        return *this;
107
1.53k
    }
_ZN5doris14TaggableLogger5errorIRNS_6StatusEEERS0_OT_
Line
Count
Source
104
1.53k
    TaggableLogger& error(E&& error) {
105
1.53k
        _msg.stream() << "|error=" << error;
106
1.53k
        return *this;
107
1.53k
    }
Unexecuted instantiation: _ZN5doris14TaggableLogger5errorIRNS_7TStatusEEERS0_OT_
108
109
private:
110
    google::LogMessage _msg;
111
};
112
113
// Very very important!!!!
114
// Never define LOG_DEBUG or LOG_TRACE. because the tagged logging method will
115
// always generated string and then check the log level, its performane is bad.
116
// glog's original method will first check log level if it is not satisfied,
117
// the log message is not generated.
118
1.93M
#define LOG_INFO TaggableLogger(__FILE__, __LINE__, google::GLOG_INFO)
119
4.99k
#define LOG_WARNING TaggableLogger(__FILE__, __LINE__, google::GLOG_WARNING)
120
#define LOG_ERROR TaggableLogger(__FILE__, __LINE__, google::GLOG_ERROR)
121
0
#define LOG_FATAL TaggableLogger(__FILE__, __LINE__, google::GLOG_FATAL)
122
123
} // namespace doris