MySQL 8.0.29
Source Code Documentation
log_filter.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2017, 2021, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef MYSQLROUTER_LOG_FILTER_INCLUDED
26#define MYSQLROUTER_LOG_FILTER_INCLUDED
27
29
30#include <string>
31#include <vector>
32
33#include <regex>
34using regex_search_and_replace_patterns = std::pair<std::regex, std::string>;
35
36namespace mysqlrouter {
37
38/*
39 * A LogFilter allows to replace substring with '***'.
40 */
42 public:
43 static const char kFillCharacter;
44 static const unsigned int kFillSize = 3;
45
46 /*
47 * @param statement The string to be filtered.
48 *
49 * @return filtered string
50 */
51 std::string filter(std::string statement) const;
52
53 /*
54 * @param pattern The string with pattern to match
55 * @param group_indices The vector with indices of groups that will be
56 * replaced with '***'
57 */
58 void add_pattern(const std::string &pattern,
59 const std::vector<size_t> &group_indices);
60
61 /*
62 * @param pattern The string with regex pattern to match
63 * @param replacement Replacement string for matched pattern. You can use
64 * $<nr> notation to insert captured groups from regex search pattern
65 */
66 void add_pattern(const std::string &pattern, const std::string &replacement);
67
68 private:
69 std::vector<regex_search_and_replace_patterns> patterns_;
70};
71
72/**
73 * A SQLLogFilter allows to replace substrings defined by a set of hardcoded
74 * regular expressions with '***'.
75 */
76class SQLLogFilter : public LogFilter {
77 public:
78 /*
79 * Adds default patterns defined as regular expressions.
80 */
82};
83
84} // namespace mysqlrouter
85
86#endif // LOG_FILTER_INCLUDED
Definition: log_filter.h:41
std::vector< regex_search_and_replace_patterns > patterns_
Definition: log_filter.h:69
void add_pattern(const std::string &pattern, const std::vector< size_t > &group_indices)
static const char kFillCharacter
Definition: log_filter.h:43
A SQLLogFilter allows to replace substrings defined by a set of hardcoded regular expressions with '*...
Definition: log_filter.h:76
void add_default_sql_patterns()
Definition: log_filter.cc:49
std::pair< std::regex, std::string > regex_search_and_replace_patterns
Definition: log_filter.h:34
Definition: dim.h:357
#define ROUTER_LIB_EXPORT
Definition: router_export.h:15
Definition: mysqlslap.cc:213