Skip to content

Commit c20a6db

Browse files
author
Andrew Nikitin
committed
Revert "[INDY-1225] Implemented compression, increased log rotation interval (hyperledger#607)"
This reverts commit 159a987. Signed-off-by: Andrew Nikitin <[email protected]>
1 parent 55232e1 commit c20a6db

File tree

5 files changed

+20
-61
lines changed

5 files changed

+20
-61
lines changed

plenum/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,10 @@
149149

150150

151151
# Log configuration
152-
logRotationWhen = 'W6'
152+
logRotationWhen = 'D'
153153
logRotationInterval = 1
154-
logRotationBackupCount = 50
154+
logRotationBackupCount = 10
155155
logRotationMaxBytes = 100 * 1024 * 1024
156-
logRotationCompress = True
157156
logFormat = '{asctime:s} | {levelname:8s} | {filename:20s} ({lineno: >4}) | {funcName:s} | {message:s}'
158157
logFormatStyle = '{'
159158
logLevel = logging.NOTSET

plenum/test/test_log_rotation.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,34 @@
22
import logging
33
import time
44
import collections
5-
import gzip
6-
import pytest
75

86
from stp_core.common.logging.TimeAndSizeRotatingFileHandler \
97
import TimeAndSizeRotatingFileHandler
108
from stp_core.common.log import Logger
119

1210

13-
@pytest.fixture(params=[False, True], ids=["plain", "compressed"])
14-
def log_compression(request):
15-
return request.param
16-
17-
def test_default_log_rotation_config_is_correct(tdir_for_func):
18-
logDirPath = tdir_for_func
19-
logFile = os.path.join(logDirPath, "log")
20-
logger = Logger()
21-
22-
# Assert this doesn't fail
23-
logger.enableFileLogging(logFile)
24-
25-
26-
def test_time_log_rotation(tdir_for_func, log_compression):
11+
def test_time_log_rotation(tdir_for_func):
2712
logDirPath = tdir_for_func
2813
logFile = os.path.join(logDirPath, "log")
2914
logger = logging.getLogger('test_time_log_rotation-logger')
3015

3116
logger.setLevel(logging.DEBUG)
32-
handler = TimeAndSizeRotatingFileHandler(
33-
logFile, interval=1, when='s', compress=log_compression)
17+
handler = TimeAndSizeRotatingFileHandler(logFile, interval=1, when='s')
3418
logger.addHandler(handler)
3519
for i in range(3):
3620
time.sleep(1)
3721
logger.debug("line")
3822
assert len(os.listdir(logDirPath)) == 4 # initial + 3 new
3923

4024

41-
def test_size_log_rotation(tdir_for_func, log_compression):
25+
def test_size_log_rotation(tdir_for_func):
4226
logDirPath = tdir_for_func
4327
logFile = os.path.join(logDirPath, "log")
4428
logger = logging.getLogger('test_time_log_rotation-logger')
4529

4630
logger.setLevel(logging.DEBUG)
4731
handler = TimeAndSizeRotatingFileHandler(
48-
logFile, maxBytes=(4 + len(os.linesep)) * 4 + 1, compress=log_compression)
32+
logFile, maxBytes=(4 + len(os.linesep)) * 4 + 1)
4933
logger.addHandler(handler)
5034
for i in range(20):
5135
logger.debug("line")
@@ -54,14 +38,14 @@ def test_size_log_rotation(tdir_for_func, log_compression):
5438
assert len(os.listdir(logDirPath)) == 5
5539

5640

57-
def test_time_and_size_log_rotation(tdir_for_func, log_compression):
41+
def test_time_and_size_log_rotation(tdir_for_func):
5842
logDirPath = tdir_for_func
5943
logFile = os.path.join(logDirPath, "log")
6044
logger = logging.getLogger('test_time_and_size_log_rotation-logger')
6145

6246
logger.setLevel(logging.DEBUG)
6347
handler = TimeAndSizeRotatingFileHandler(
64-
logFile, maxBytes=(4 + len(os.linesep)) * 4 + 1, interval=1, when="s", compress=log_compression)
48+
logFile, maxBytes=(4 + len(os.linesep)) * 4 + 1, interval=1, when="s")
6549
logger.addHandler(handler)
6650

6751
for i in range(20):
@@ -74,7 +58,7 @@ def test_time_and_size_log_rotation(tdir_for_func, log_compression):
7458
assert len(os.listdir(logDirPath)) == 8
7559

7660

77-
def test_time_and_size_log_rotation1(tdir_for_func, log_compression):
61+
def test_time_and_size_log_rotation1(tdir_for_func):
7862
log_dir_path = tdir_for_func
7963
logFile = os.path.join(log_dir_path, "log")
8064
logger = logging.getLogger('test_time_and_size_log_rotation-logger1')
@@ -90,7 +74,7 @@ def test_time_and_size_log_rotation1(tdir_for_func, log_compression):
9074
handler = TimeAndSizeRotatingFileHandler(
9175
logFile,
9276
maxBytes=(record_length + len(os.linesep)) * record_per_file + 1,
93-
interval=1, when="h", backupCount=backup_count, utc=True, compress=log_compression)
77+
interval=1, when="h", backupCount=backup_count, utc=True)
9478
logger.addHandler(handler)
9579

9680
for i in range(1, record_count + 1):
@@ -107,7 +91,6 @@ def test_time_and_size_log_rotation1(tdir_for_func, log_compression):
10791
assert len(cir_buffer) == len(circ_buffer_set)
10892
assert len(os.listdir(log_dir_path)) == (backup_count + 1)
10993
for file_name in os.listdir(log_dir_path):
110-
open_fn = gzip.open if file_name.endswith(".gz") else open
111-
with open_fn(os.path.join(log_dir_path, file_name), "rt") as file:
94+
with open(os.path.join(log_dir_path, file_name)) as file:
11295
for line in file.readlines():
11396
assert line.strip() in circ_buffer_set

stp_core/common/log.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def enableFileLogging(self, filename):
9797
interval=self._config.logRotationInterval,
9898
backupCount=self._config.logRotationBackupCount,
9999
utc=True,
100-
maxBytes=self._config.logRotationMaxBytes,
101-
compress=self._config.logRotationCompress)
100+
maxBytes=self._config.logRotationMaxBytes)
102101
self._setHandler('file', new)
103102

104103
def _setHandler(self, typ: str, new_handler):

stp_core/common/logging/TimeAndSizeRotatingFileHandler.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import gzip
32
from logging.handlers import TimedRotatingFileHandler
43
from logging.handlers import RotatingFileHandler
54

@@ -8,33 +7,21 @@ class TimeAndSizeRotatingFileHandler(TimedRotatingFileHandler, RotatingFileHandl
87

98
def __init__(self, filename, when='h', interval=1, backupCount=0,
109
encoding=None, delay=False, utc=False, atTime=None,
11-
maxBytes=0, compress=False):
10+
maxBytes=0):
1211

1312
TimedRotatingFileHandler.__init__(self, filename, when, interval,
1413
backupCount, encoding, delay,
1514
utc, atTime)
1615
self.maxBytes = maxBytes
17-
self.compress = compress
1816

1917
def shouldRollover(self, record):
2018
return bool(TimedRotatingFileHandler.shouldRollover(self, record)) or \
2119
bool(RotatingFileHandler.shouldRollover(self, record))
2220

23-
def rotate(self, source, dest):
24-
source_gz = source.endswith(".gz")
25-
dest_gz = dest.endswith(".gz")
26-
if source_gz == dest_gz:
27-
os.rename(source, dest)
28-
return
29-
# Assuming that not source_gz and dest_gz
30-
with open(source, 'rb') as f_in, gzip.open(dest, 'wb') as f_out:
31-
f_out.writelines(f_in)
32-
os.remove(source)
33-
3421
def rotation_filename(self, default_name: str):
35-
compressed_name = self._compressed_filename(default_name)
36-
if not os.path.exists(compressed_name):
37-
return compressed_name
22+
23+
if not os.path.exists(default_name):
24+
return default_name
3825

3926
dir = os.path.dirname(default_name)
4027
defaultFileName = os.path.basename(default_name)
@@ -46,19 +33,13 @@ def rotation_filename(self, default_name: str):
4633
index = self._file_index(fileName)
4734
if index > maxIndex:
4835
maxIndex = index
49-
return self._compressed_filename("{}.{}".format(default_name, maxIndex + 1))
50-
51-
def _compressed_filename(self, file_name):
52-
return "{}.gz".format(file_name) if self.compress else file_name
36+
return "{}.{}".format(default_name, maxIndex + 1)
5337

5438
@staticmethod
5539
def _file_index(file_name):
5640
split = file_name.split(".")
57-
index = split[-1]
58-
if index == "gz":
59-
index = split[-2]
6041
try:
61-
return int(index)
42+
return int(split[-1])
6243
except ValueError:
6344
return 0
6445

@@ -78,8 +59,6 @@ def getFilesToDelete(self):
7859
for fileName in fileNames:
7960
if fileName[:plen] == prefix:
8061
suffix = fileName[plen:]
81-
if suffix.endswith(".gz"):
82-
suffix = suffix[:-3]
8362
if self.extMatch.match(suffix):
8463
result.append(os.path.join(dirName, fileName))
8564
if len(result) <= self.backupCount:

stp_core/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
baseDir = os.getcwd()
88

99
# Log configuration
10-
logRotationWhen = 'W6'
10+
logRotationWhen = 'D'
1111
logRotationInterval = 1
12-
logRotationBackupCount = 50
12+
logRotationBackupCount = 10
1313
logRotationMaxBytes = 100 * 1024 * 1024
14-
logRotationCompress = True
1514
logFormat = '{asctime:s} | {levelname:8s} | {filename:20s} ({lineno:d}) | {funcName:s} | {message:s}'
1615
logFormatStyle = '{'
1716

0 commit comments

Comments
 (0)