MySQL 9.1.0
Source Code Documentation
log_filter.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2017, 2024, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLROUTER_LOG_FILTER_INCLUDED
27#define MYSQLROUTER_LOG_FILTER_INCLUDED
28
30
31#include <string>
32#include <vector>
33
34#include <regex>
35using regex_search_and_replace_patterns = std::pair<std::regex, std::string>;
36
37namespace mysqlrouter {
38
39/*
40 * A LogFilter allows to replace substring with '***'.
41 */
43 public:
44 static const char kFillCharacter;
45 static const unsigned int kFillSize = 3;
46
47 /*
48 * @param statement The string to be filtered.
49 *
50 * @return filtered string
51 */
52 std::string filter(std::string statement) const;
53
54 /*
55 * @param pattern The string with pattern to match
56 * @param group_indices The vector with indices of groups that will be
57 * replaced with '***'
58 */
59 void add_pattern(const std::string &pattern,
60 const std::vector<size_t> &group_indices);
61
62 /*
63 * @param pattern The string with regex pattern to match
64 * @param replacement Replacement string for matched pattern. You can use
65 * $<nr> notation to insert captured groups from regex search pattern
66 */
67 void add_pattern(const std::string &pattern, const std::string &replacement);
68
69 private:
70 std::vector<regex_search_and_replace_patterns> patterns_;
71};
72
73/**
74 * A SQLLogFilter allows to replace substrings defined by a set of hardcoded
75 * regular expressions with '***'.
76 */
77class SQLLogFilter : public LogFilter {
78 public:
79 /*
80 * Adds default patterns defined as regular expressions.
81 */
83};
84
85} // namespace mysqlrouter
86
87#endif // LOG_FILTER_INCLUDED
Definition: log_filter.h:42
std::vector< regex_search_and_replace_patterns > patterns_
Definition: log_filter.h:70
void add_pattern(const std::string &pattern, const std::vector< size_t > &group_indices)
static const char kFillCharacter
Definition: log_filter.h:44
A SQLLogFilter allows to replace substrings defined by a set of hardcoded regular expressions with '*...
Definition: log_filter.h:77
void add_default_sql_patterns()
Definition: log_filter.cc:50
std::pair< std::regex, std::string > regex_search_and_replace_patterns
Definition: log_filter.h:35
Definition: base64.h:43
#define ROUTER_MYSQL_EXPORT
Definition: router_mysql_export.h:15
Definition: mysqlslap.cc:219