Skip to content

Commit e96e0a0

Browse files
author
Artyom Abakumov
committed
Add ability to specify database string type in trace.conf
1 parent 6af07d0 commit e96e0a0

File tree

2 files changed

+82
-43
lines changed

2 files changed

+82
-43
lines changed

src/utilities/ntrace/TraceConfiguration.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ void TraceCfgReader::readTraceConfiguration(const char* text,
7070

7171
#define ERROR_PREFIX "error while parsing trace configuration\n\t"
7272

73+
enum class AliasType
74+
{
75+
DETECT,
76+
NAME,
77+
REGEX
78+
};
79+
inline constexpr std::string_view REGEX_PREFIX = "regex ";
80+
inline constexpr std::string_view NAME_PREFIX = "name ";
81+
7382
void TraceCfgReader::readConfig()
7483
{
7584
ConfigFile cfgFile(ConfigFile::USE_TEXT, m_text, ConfigFile::HAS_SUB_CONF | ConfigFile::NATIVE_ORDER
@@ -127,18 +136,41 @@ void TraceCfgReader::readConfig()
127136
}
128137
else if (isDatabase && !m_databaseName.empty())
129138
{
130-
PathName noQuotePattern = pattern.ToPathName();
139+
PathName noQuotePattern;
140+
141+
AliasType specifier = AliasType::DETECT;
142+
const std::string_view patternView(pattern.data(), pattern.length());
143+
144+
// Check for "name" or "regex" specific in the path.
145+
// Compare path in both ways if specifier is not specified
146+
if (patternView.find_first_of(REGEX_PREFIX) == 0)
147+
{
148+
noQuotePattern.assign(pattern.data() + REGEX_PREFIX.length());
149+
specifier = AliasType::REGEX;
150+
}
151+
else if (patternView.find_first_of(NAME_PREFIX) == 0)
152+
{
153+
noQuotePattern.assign(pattern.data() + NAME_PREFIX.length());
154+
specifier = AliasType::NAME;
155+
}
156+
else
157+
{
158+
noQuotePattern = pattern.ToPathName();
159+
}
160+
131161
noQuotePattern.alltrim(" '\'");
132162
PathName expandedName;
133163

134-
if (m_databaseName == noQuotePattern ||
164+
if (specifier != AliasType::REGEX && (m_databaseName == noQuotePattern ||
135165
(expandDatabaseName(noQuotePattern, expandedName, nullptr),
136-
m_databaseName == expandedName) )
166+
m_databaseName == expandedName) ))
137167
{
168+
// Compare by name
138169
match = exactMatch = true;
139170
}
140-
else
171+
else if (specifier != AliasType::NAME)
141172
{
173+
// Compare by regex
142174
bool regExpOk = false;
143175
try
144176
{

src/utilities/ntrace/fbtrace.conf

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# expression which is matched against fully qualified database path name.
1212
#
1313
# For log file name Sed syntax for substitutions is supported.
14-
# I.e. \0 - whole matched string, \1 ... \9 - parenthesis subexpressions.
14+
# I.e. \0 - whole matched string, \1 ... \9 - parenthesis subexpressions.
1515
# \\ is backslash.
1616
#
17-
# String values should be enclosed into double quotes if contains
17+
# String values should be enclosed into double quotes if contains
1818
# spaces embedded, for example:
1919
# log_filename "C:\\Documents and Settings\\Firebird\\My Documents\\trace.log"
2020
# include_filter "Database Stats"
@@ -24,6 +24,13 @@
2424
# database = (%[\\/](e[[:DIGIT:]]{2}).fdb)
2525
# type
2626
# database = (%[\\/](e[[:DIGIT:]]{{2}}).fdb)
27+
#
28+
# It is also possible to specify exactly what type of database string is expected
29+
# For example:
30+
# database = name /var/dbs/primary-db.fdb
31+
# type
32+
# database = regex (%[\\/](e[[:DIGIT:]]{{2}}).fdb)
33+
2734

2835

2936
database
@@ -35,72 +42,72 @@ database
3542
# Operations log file name. For use by system audit trace only
3643
#log_filename = name
3744

38-
# Maximum size of log file (megabytes). Used by system audit trace for
45+
# Maximum size of log file (megabytes). Used by system audit trace for
3946
# log's rotation : when current log file reached this limit it is renamed
40-
# using current date and time and new log file is created. Value of zero
47+
# using current date and time and new log file is created. Value of zero
4148
# means that the log file size is unlimited and rotation will never happen.
4249
#max_log_size = 0
4350

4451

45-
# SQL query filters.
52+
# SQL query filters.
4653
#
47-
# Only SQL statements falling under given regular expression are reported
54+
# Only SQL statements falling under given regular expression are reported
4855
# in the log.
49-
#include_filter
56+
#include_filter
5057

51-
# SQL statements falling under given regular expression are NOT reported
58+
# SQL statements falling under given regular expression are NOT reported
5259
# in the log.
53-
#exclude_filter
60+
#exclude_filter
5461

5562

56-
# Put attach/detach log records
63+
# Put attach/detach log records
5764
#log_connections = false
5865

59-
# Trace only given connection id. If zero - trace all connections
66+
# Trace only given connection id. If zero - trace all connections
6067
#connection_id = 0
6168

62-
# Put transaction start/end records
69+
# Put transaction start/end records
6370
#log_transactions = false
6471

6572

66-
# Put sql statement prepare records
73+
# Put sql statement prepare records
6774
#log_statement_prepare = false
6875

69-
# Put sql statement free records
76+
# Put sql statement free records
7077
#log_statement_free = false
7178

72-
# Put sql statement execution start records
79+
# Put sql statement execution start records
7380
#log_statement_start = false
74-
75-
# Put sql statement execution finish\fetch to eof records
81+
82+
# Put sql statement execution finish\fetch to eof records
7683
#log_statement_finish = false
7784

7885

7986
# Put record when stored procedure is being compiled
8087
#log_procedure_compile = false
8188

82-
# Put record when stored procedure is start execution
89+
# Put record when stored procedure is start execution
8390
#log_procedure_start = false
8491

85-
# Put record when stored procedure is finish execution
92+
# Put record when stored procedure is finish execution
8693
#log_procedure_finish = false
8794

8895
# Put record when stored function is being compiled
8996
#log_function_compile = false
9097

91-
# Put record when stored function is start execution
98+
# Put record when stored function is start execution
9299
#log_function_start = false
93100

94-
# Put record when stored function is finish execution
101+
# Put record when stored function is finish execution
95102
#log_function_finish = false
96103

97104
# Put record when trigger is being compiled
98105
#log_trigger_compile = false
99106

100-
# Put trigger execute records
107+
# Put trigger execute records
101108
#log_trigger_start = false
102109

103-
# Put trigger execute records
110+
# Put trigger execute records
104111
#log_trigger_finish = false
105112

106113

@@ -142,13 +149,13 @@ database
142149
#print_perf = false
143150

144151

145-
# Put blr requests compile/execute records
152+
# Put blr requests compile/execute records
146153
#log_blr_requests = false
147154

148155
# Print blr requests or not
149156
#print_blr = false
150157

151-
# Put dyn requests execute records
158+
# Put dyn requests execute records
152159
#log_dyn_requests = false
153160

154161
# Print dyn requests or not
@@ -158,27 +165,27 @@ database
158165
# Put xxx_finish record only if its timing exceeds this number of milliseconds
159166
#time_threshold = 100
160167

161-
# Maximum length of SQL string logged
168+
# Maximum length of SQL string logged
162169
#max_sql_length = 300
163170

164-
# Maximum length of blr request logged
171+
# Maximum length of blr request logged
165172
#max_blr_length = 500
166173

167-
# Maximum length of dyn request logged
174+
# Maximum length of dyn request logged
168175
#max_dyn_length = 500
169176

170-
# Maximum length of individual string argument we log
177+
# Maximum length of individual string argument we log
171178
#max_arg_length = 80
172179

173-
# Maximum number of query arguments to put in log
180+
# Maximum number of query arguments to put in log
174181
#max_arg_count = 30
175182
}
176183

177184

178185

179186
# default services section
180187
#
181-
# List of names of currently existing Firebird services (to use with service
188+
# List of names of currently existing Firebird services (to use with service
182189
# filters below) :
183190
# Backup Database
184191
# Restore Database
@@ -203,27 +210,27 @@ database
203210
# Display User with Admin Info
204211
# Validate Database
205212
#
206-
services
213+
services
207214
{
208215
# Do we trace services events or not
209216
#enabled = false
210217

211218
# Operations log file name. For use by system audit trace only
212219
#log_filename = name
213220

214-
# Maximum size of log file (megabytes). Used by system audit trace for
215-
# log's rotation
221+
# Maximum size of log file (megabytes). Used by system audit trace for
222+
# log's rotation
216223
#max_log_size = 0
217224

218225
# Services filters.
219226
#
220-
# Only services whose names fall under given regular expression are
227+
# Only services whose names fall under given regular expression are
221228
# reported in the log.
222-
#include_filter
229+
#include_filter
223230

224-
# Services whose names fall under given regular expression are NOT
231+
# Services whose names fall under given regular expression are NOT
225232
# reported in the log.
226-
#exclude_filter
233+
#exclude_filter
227234

228235
# Put service attach, detach and start records
229236
#log_services = false
@@ -265,7 +272,7 @@ database = %[\\/]my_database.fdb
265272

266273

267274
# Enable logging for test.fdb, azk2.fdb and rulez.fdb in any directory
268-
# into log file name matching database name - test.log, azk2.log and
275+
# into log file name matching database name - test.log, azk2.log and
269276
# rulez.log appropriately
270277
#
271278
database = %[\\/](test|azk2|rulez).fdb

0 commit comments

Comments
 (0)