1 
2 /**
3  *    Copyright (C) 2018-present MongoDB, Inc.
4  *
5  *    This program is free software: you can redistribute it and/or modify
6  *    it under the terms of the Server Side Public License, version 1,
7  *    as published by MongoDB, Inc.
8  *
9  *    This program is distributed in the hope that it will be useful,
10  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *    Server Side Public License for more details.
13  *
14  *    You should have received a copy of the Server Side Public License
15  *    along with this program. If not, see
16  *    <http://www.mongodb.com/licensing/server-side-public-license>.
17  *
18  *    As a special exception, the copyright holders give permission to link the
19  *    code of portions of this program with the OpenSSL library under certain
20  *    conditions as described in each individual source file and distribute
21  *    linked combinations including the program with the OpenSSL library. You
22  *    must comply with the Server Side Public License in all respects for
23  *    all of the code used other than as permitted herein. If you modify file(s)
24  *    with this exception, you may extend this exception to your version of the
25  *    file(s), but you are not obligated to do so. If you do not wish to do so,
26  *    delete this exception statement from your version. If you delete this
27  *    exception statement from all source files in the program, then also delete
28  *    it in the license file.
29  */
30 
31 #pragma once
32 
33 #include <iosfwd>
34 #include <string>
35 
36 #include "mongo/base/string_data.h"
37 
38 namespace mongo {
39 namespace logger {
40 
41 /**
42  * Log components.
43  * Debug messages logged using the LOG() or MONGO_LOG_COMPONENT().
44  * Macros may be associated with one or more log components.
45  */
46 class LogComponent {
47 public:
48     enum Value {
49         kDefault = 0,
50         kAccessControl,
51         kCommand,
52         kControl,
53         kExecutor,
54         kGeo,
55         kIndex,
56         kNetwork,
57         kQuery,
58         kReplication,
59         kReplicationHeartbeats,
60         kReplicationRollback,
61         kSharding,
62         kShardingCatalogRefresh,
63         kStorage,
64         kJournal,
65         kWrite,
66         kFTDC,
67         kASIO,
68         kBridge,
69         kTracking,
70         kNumLogComponents
71     };
72 
LogComponent(Value value)73     /* implicit */ LogComponent(Value value) : _value(value) {}
74 
Value()75     operator Value() const {
76         return _value;
77     }
78 
79     /**
80      * Returns parent component.
81      * Returns kNumComponents if parent component is not defined (for kDefault or
82      * kNumLogComponents).
83      */
84     LogComponent parent() const;
85 
86     /**
87      * Returns short name as a StringData.
88      */
89     StringData toStringData() const;
90 
91     /**
92      * Returns short name of log component.
93      * Used to generate server parameter names in the format "logLevel_<component short name>".
94      */
95     std::string getShortName() const;
96 
97     /**
98      * Returns dotted name of log component - short name prefixed by dot-separated names of
99      * ancestors.
100      * Used to generate command line and config file option names.
101      */
102     std::string getDottedName() const;
103 
104     /**
105      * Returns name suitable for inclusion in formatted log message.
106      * This is derived from upper-casing the short name with some padding to
107      * fit into a fixed length field.
108      */
109     StringData getNameForLog() const;
110 
111 private:
112     Value _value;
113 };
114 
115 std::ostream& operator<<(std::ostream& os, LogComponent component);
116 
117 }  // namespace logger
118 }  // namespace mongo
119