1
1
# -*- coding: utf-8 -*-
2
2
3
3
import struct
4
+ import logging
4
5
from distutils .version import LooseVersion
5
6
6
7
import pymysql
@@ -144,7 +145,8 @@ def __init__(self, connection_settings, server_id,
144
145
is_mariadb = False ,
145
146
annotate_rows_event = False ,
146
147
ignore_decode_errors = False ,
147
- verify_checksum = False ,):
148
+ verify_checksum = False ,
149
+ enable_logging = True ,):
148
150
"""
149
151
Attributes:
150
152
ctl_connection_settings: Connection settings for cluster holding
@@ -187,6 +189,8 @@ def __init__(self, connection_settings, server_id,
187
189
ignore_decode_errors: If true, any decode errors encountered
188
190
when reading column data will be ignored.
189
191
verify_checksum: If true, verify events read from the binary log by examining checksums.
192
+ enable_logging: When set to True, logs various details helpful for debugging and monitoring
193
+ When set to False, logging is disabled to enhance performance.
190
194
"""
191
195
192
196
self .__connection_settings = connection_settings
@@ -228,6 +232,8 @@ def __init__(self, connection_settings, server_id,
228
232
self .skip_to_timestamp = skip_to_timestamp
229
233
self .is_mariadb = is_mariadb
230
234
self .__annotate_rows_event = annotate_rows_event
235
+ if enable_logging :
236
+ self .__log_valid_parameters ()
231
237
232
238
if end_log_pos :
233
239
self .is_past_end_log_pos = False
@@ -368,9 +374,11 @@ def __connect_to_stream(self):
368
374
369
375
if not self .__blocking :
370
376
flags |= 0x01 # BINLOG_DUMP_NON_BLOCK
377
+
371
378
prelude += struct .pack ('<H' , flags )
372
379
373
380
prelude += struct .pack ('<I' , self .__server_id )
381
+
374
382
prelude += self .log_file .encode ()
375
383
else :
376
384
if self .is_mariadb :
@@ -674,7 +682,7 @@ def __get_table_information(self, schema, table):
674
682
continue
675
683
else :
676
684
raise error
677
-
685
+
678
686
def __get_dbms (self ):
679
687
if not self .__connected_ctl :
680
688
self .__connect_to_ctl ()
@@ -687,5 +695,20 @@ def __get_dbms(self):
687
695
return 'mariadb'
688
696
return 'mysql'
689
697
698
+ def __log_valid_parameters (self ):
699
+ ignored = ["allowed_events" , "table_map" ]
700
+ for parameter , value in self .__dict__ .items ():
701
+ if parameter .startswith ("_BinLogStreamReader__" ):
702
+ parameter = parameter .replace ("_BinLogStreamReader__" , "" )
703
+ if parameter in ignored or not value :
704
+ continue
705
+ if type (value ) == frozenset :
706
+ string_list = [str (item ).split ()[- 1 ][:- 2 ].split ('.' )[2 ] for item in value ]
707
+ items = ", " .join (string_list )
708
+ comment = f"{ parameter } : [{ items } ]"
709
+ else :
710
+ comment = f"{ parameter } : { value } "
711
+ logging .info (comment )
712
+
690
713
def __iter__ (self ):
691
714
return iter (self .fetchone , None )
0 commit comments