Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 18691ce

Browse files
committed
Use global configuration for logging
1 parent 2c74d50 commit 18691ce

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

testgres/testgres.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class TestgresConfig:
8585
# shall we remove EVERYTHING (including logs)?
8686
node_cleanup_full = True
8787

88+
# use python logging
89+
use_python_logging = False
90+
8891

8992
class TestgresException(Exception):
9093
"""
@@ -369,14 +372,13 @@ def _prepare_dir(self, destroy):
369372

370373
return base_dir
371374

372-
def spawn_primary(self, name, destroy=True, use_logging=False):
375+
def spawn_primary(self, name, destroy=True):
373376
"""
374377
Create a primary node from a backup.
375378
376379
Args:
377380
name: name for a new node.
378381
destroy: should we convert this backup into a node?
379-
use_logging: enable python logging.
380382
381383
Returns:
382384
New instance of PostgresNode.
@@ -387,8 +389,7 @@ def spawn_primary(self, name, destroy=True, use_logging=False):
387389
# Build a new PostgresNode
388390
node = PostgresNode(name=name,
389391
base_dir=base_dir,
390-
master=self.original_node,
391-
use_logging=use_logging)
392+
master=self.original_node)
392393

393394
# New nodes should always remove dir tree
394395
node.should_rm_dirs = True
@@ -398,20 +399,19 @@ def spawn_primary(self, name, destroy=True, use_logging=False):
398399

399400
return node
400401

401-
def spawn_replica(self, name, destroy=True, use_logging=False):
402+
def spawn_replica(self, name, destroy=True):
402403
"""
403404
Create a replica of the original node from a backup.
404405
405406
Args:
406407
name: name for a new node.
407408
destroy: should we convert this backup into a node?
408-
use_logging: enable python logging.
409409
410410
Returns:
411411
New instance of PostgresNode.
412412
"""
413413

414-
node = self.spawn_primary(name, destroy, use_logging=use_logging)
414+
node = self.spawn_primary(name, destroy)
415415
node._create_recovery_conf(self.original_node)
416416

417417
return node
@@ -442,7 +442,6 @@ def __init__(self,
442442
name,
443443
port=None,
444444
base_dir=None,
445-
use_logging=False,
446445
master=None):
447446
global bound_ports
448447

@@ -453,7 +452,6 @@ def __init__(self,
453452
self.base_dir = base_dir
454453
self.should_free_port = port is None
455454
self.should_rm_dirs = base_dir is None
456-
self.use_logging = use_logging
457455
self.logger = None
458456

459457
# create directories if needed
@@ -699,7 +697,7 @@ def start(self, params=[]):
699697
"""
700698

701699
# choose log_filename
702-
if self.use_logging:
700+
if TestgresConfig.use_python_logging:
703701
tmpfile = tempfile.NamedTemporaryFile('w', dir=self.logs_dir, delete=False)
704702
log_filename = tmpfile.name
705703

@@ -1070,20 +1068,18 @@ def backup(self, username=None, xlog_method=DEFAULT_XLOG_METHOD):
10701068
xlog_method=xlog_method)
10711069

10721070
def replicate(self, name, username=None,
1073-
xlog_method=DEFAULT_XLOG_METHOD,
1074-
use_logging=False):
1071+
xlog_method=DEFAULT_XLOG_METHOD):
10751072
"""
10761073
Create a binary replica of this node.
10771074
10781075
Args:
10791076
name: replica's name.
10801077
username: database user name.
10811078
xlog_method: a method for collecting the logs ('fetch' | 'stream').
1082-
use_logging: enable python logging.
10831079
"""
10841080

10851081
backup = self.backup(username=username, xlog_method=xlog_method)
1086-
return backup.spawn_replica(name, use_logging=use_logging)
1082+
return backup.spawn_replica(name)
10871083

10881084
async def catchup(self, username=None):
10891085
"""
@@ -1374,20 +1370,19 @@ def get_pg_config():
13741370
return data
13751371

13761372

1377-
def get_new_node(name, base_dir=None, use_logging=False):
1373+
def get_new_node(name, base_dir=None):
13781374
"""
13791375
Create a new node (select port automatically).
13801376
13811377
Args:
13821378
name: node's name.
13831379
base_dir: path to node's data directory.
1384-
use_logging: should we use custom logger?
13851380
13861381
Returns:
13871382
An instance of PostgresNode.
13881383
"""
13891384

1390-
return PostgresNode(name=name, base_dir=base_dir, use_logging=use_logging)
1385+
return PostgresNode(name=name, base_dir=base_dir)
13911386

13921387

13931388
def configure_testgres(**options):

tests/test_simple.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,9 @@ async def test_logging(self):
437437
}
438438

439439
logging.config.dictConfig(log_conf)
440+
configure_testgres(use_python_logging=True)
440441

441-
with get_new_node('master', use_logging=True) as master:
442+
with get_new_node('master') as master:
442443
master.init().start()
443444

444445
# execute a dummy query a few times
@@ -454,6 +455,8 @@ async def test_logging(self):
454455
lines = log.readlines()
455456
self.assertTrue(any('select' in s for s in lines))
456457

458+
configure_testgres(use_python_logging=False)
459+
457460
async def test_poll_query_until(self):
458461
with get_new_node('master') as node:
459462
node.init().start()

0 commit comments

Comments
 (0)