]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/util/log-cli.hh
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / seastar / include / seastar / util / log-cli.hh
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * 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 /*
19 * Copyright (C) 2017 ScyllaDB
20 */
21
22 #pragma once
23
24 #include <seastar/util/log.hh>
25 #include <seastar/util/program-options.hh>
26
27 #include <seastar/core/sstring.hh>
28
29 #include <boost/program_options.hpp>
30
31 #include <algorithm>
32 #include <unordered_map>
33
34 /// \addtogroup logging
35 /// @{
36 namespace seastar {
37
38 ///
39 /// \brief Configure application logging at run-time with program options.
40 ///
41 namespace log_cli {
42
43 ///
44 /// \brief Options for controlling logging at run-time.
45 ///
46 boost::program_options::options_description get_options_description();
47
48 using log_level_map = std::unordered_map<sstring, log_level>;
49
50 /// Logging configuration.
51 struct options : public program_options::option_group {
52 /// \brief Default log level for log messages.
53 ///
54 /// Valid values are trace, debug, info, warn, error.
55 /// Default: \p info
56 /// \see \ref log_level.
57 program_options::value<log_level> default_log_level;
58 /// \brief Map of logger name to log level.
59 ///
60 /// The format is `NAME0=LEVEL0[:NAME1=LEVEL1:...]`.
61 /// Valid logger names can be queried with \p --help-loggers.
62 /// This option can be specified multiple times.
63 program_options::value<log_level_map> logger_log_level;
64 /// Select timestamp style for stdout logs.
65 ///
66 /// Default: \p real.
67 /// \see logger_timestamp_style.
68 program_options::value<logger_timestamp_style> logger_stdout_timestamps;
69 /// \brief Send log output to output stream.
70 ///
71 /// As selected by \ref logger_ostream_type.
72 /// Default: \p true.
73 program_options::value<bool> log_to_stdout;
74 /// Send log output to.
75 ///
76 /// Default: \p stderr.
77 /// \see \ref seastar::logger_ostream_type.
78 program_options::value<seastar::logger_ostream_type> logger_ostream_type;
79 /// Send log output to syslog.
80 ///
81 /// Default: \p false.
82 program_options::value<bool> log_to_syslog;
83
84 /// Print colored tag prefix in log messages sent to output stream.
85 ///
86 /// Default: \p true.
87 program_options::value<bool> log_with_color;
88 /// \cond internal
89 options(program_options::option_group* parent_group);
90 /// \endcond
91 };
92
93 ///
94 /// \brief Print a human-friendly list of the available loggers.
95 ///
96 void print_available_loggers(std::ostream& os);
97
98 ///
99 /// \brief Parse a log-level ({error, warn, info, debug, trace}) string, throwing \c std::runtime_error for an invalid
100 /// level.
101 ///
102 log_level parse_log_level(const sstring&);
103
104 /// \cond internal
105 void parse_map_associations(const std::string& v, std::function<void(std::string, std::string)> consume_key_value);
106 /// \endcond
107
108 //
109 // \brief Parse associations from loggers to log-levels and write the resulting pairs to the output iterator.
110 //
111 // \throws \c std::runtime_error for an invalid log-level.
112 //
113 template <class OutputIter>
114 void parse_logger_levels(const program_options::string_map& levels, OutputIter out) {
115 std::for_each(levels.begin(), levels.end(), [&out](auto&& pair) {
116 *out++ = std::make_pair(pair.first, parse_log_level(pair.second));
117 });
118 }
119
120 ///
121 /// \brief Extract CLI options into a logging configuration.
122 //
123 logging_settings extract_settings(const boost::program_options::variables_map&);
124
125 ///
126 /// \brief Extract \ref options into a logging configuration.
127 ///
128 logging_settings extract_settings(const options&);
129
130 }
131
132 }
133
134 /// @}