Skip to content

Commit 31c1e32

Browse files
committed
removed unnecessary logs
1 parent 1d9d51f commit 31c1e32

File tree

10 files changed

+4
-115
lines changed

10 files changed

+4
-115
lines changed

scan_explorer_service/manifest_factory.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ def create_manifest(self, item: Union[Article, Collection]):
2222
for range in self.create_range(item):
2323
manifest.add_range(range)
2424

25-
current_app.logger.debug(f"Created manifest {manifest}")
2625
return manifest
2726

2827
def create_sequence(self, item: Union[Article, Collection]):
2928
sequence: Sequence = self.sequence()
3029
for page in item.pages:
3130
sequence.add_canvas(self.get_or_create_canvas(page))
3231

33-
current_app.logger.debug(f"Sequence {sequence}")
3432
return sequence
3533

3634
def create_range(self, item: Union[Article, Collection]):
@@ -41,13 +39,11 @@ def create_range(self, item: Union[Article, Collection]):
4139
for page in item.pages:
4240
range.add_canvas(self.get_or_create_canvas(page))
4341

44-
current_app.logger.debug(f"Range {[range]}")
4542
return [range]
4643

4744
def get_canvas_dict(self) -> Dict[str, Canvas]:
4845
if not hasattr(self, 'canvas_dict'):
4946
self.canvas_dict = {}
50-
current_app.logger.debug(f"Canvas dict {self.canvas_dict}")
5147
return self.canvas_dict
5248

5349
def get_or_create_canvas(self, page: Page):
@@ -68,7 +64,6 @@ def get_or_create_canvas(self, page: Page):
6864
annotation.on = canvas.id
6965
canvas.add_annotation(annotation)
7066
canvas_dict[page.id] = canvas
71-
current_app.logger.debug(f"Canvas {canvas}")
7267
return canvas
7368

7469
def create_image_annotation(self, page: Page):
@@ -82,7 +77,6 @@ def create_image_annotation(self, page: Page):
8277
image.format = page.format
8378
image.height = page.height
8479
image.width = page.width
85-
current_app.logger.debug(f"Annotation {annotation}")
8680
return annotation
8781

8882
def add_search_service(self, manifest: Manifest, search_url: str):

scan_explorer_service/models.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,14 @@ def __init__(self, **kwargs):
151151
@property
152152
def image_url(self):
153153
image_api_url = url_for_proxy('proxy.image_proxy', path=self.image_path)
154-
current_app.logger.debug(f'image api url: {image_api_url}')
155154
return image_api_url
156155

157156
@property
158157
def image_path(self):
159158
separator = current_app.config.get('IMAGE_API_SLASH_SUB', '%2F')
160159
image_path = separator.join(self.image_path_basic[0])
161-
current_app.logger.debug(f'color type: {self.color_type}')
162160
if self.color_type != PageColor.BW:
163161
image_path += '.tif'
164-
current_app.logger.debug(f'image path: {image_path}')
165162
return image_path
166163

167164
@property
@@ -170,15 +167,13 @@ def image_path_basic(self):
170167
image_path = [self.collection.type, self.collection.journal, self.collection.volume]
171168
image_path = [item.replace('.', '_') for item in image_path]
172169
image_path = ['bitmaps'] + image_path + ['600', self.name]
173-
current_app.logger.debug(f'image path basic: {image_path}')
174170
if self.color_type != PageColor.BW:
175171
image_format = '.tif'
176172
return image_path, image_format
177173

178174
@property
179175
def thumbnail_url(self):
180176
url = f'{self.image_url}/square/480,480/0/{self.image_color_quality}.jpg'
181-
current_app.logger.debug('thumbnail url: ' + url)
182177
return url
183178

184179
@property

scan_explorer_service/open_search.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def append_highlight(query: dict):
7474

7575
def es_search(query: dict) -> Iterator[str]:
7676
es = opensearchpy.OpenSearch(current_app.config.get('OPEN_SEARCH_URL'))
77-
current_app.logger.debug(f"Query search: {query}")
7877
resp = es.search(index=current_app.config.get(
7978
'OPEN_SEARCH_INDEX'), body=query)
8079
return resp
@@ -150,9 +149,6 @@ def page_ocr_os_search(collection_id: str, page_number:int):
150149
def aggregate_search(qs: str, aggregate_field, page, limit, sort):
151150
qs = qs.replace("&", "+")
152151
query = create_query_string_query(qs)
153-
current_app.logger.debug(f"query: {query}")
154152
query = append_aggregate(query, aggregate_field, page, limit, sort)
155-
current_app.logger.debug(f"query with aggregate: {query}")
156153
es_result = es_search(query)
157-
current_app.logger.debug(f"es_result: {es_result}")
158154
return es_result

scan_explorer_service/tests/test_proxy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ def test_fetch_object(self, mock_read_object_s3):
167167

168168
@patch('scan_explorer_service.views.image_proxy.fetch_object')
169169
def test_pdf_save_success_article(self, mock_fetch_object):
170-
# mock_read_object_s3.return_value = b'my_image_name'
171170
mock_fetch_object.return_value = b'my_image_name'
172171

173172
data = {

scan_explorer_service/utils/db_utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,18 @@ def page_overwrite(session, page):
8080
def article_thumbnail(session, id):
8181
page = session.query(Page).join(Article, Page.articles).filter(
8282
Article.id == id).order_by(Page.volume_running_page_num.asc()).first()
83-
current_app.logger.debug(f'article thumbnail {page}')
8483
return page.thumbnail_url
8584

8685
def collection_thumbnail(session, id):
8786
page = session.query(Page).filter(Page.collection_id == id).order_by(
8887
Page.volume_running_page_num.asc()).first()
89-
current_app.logger.debug(f'collection thumbnail {page.thumbnail_url}')
9088
return page.thumbnail_url
9189

9290
def page_thumbnail(session, id):
9391
page = session.query(Page).filter(Page.id == id).one()
94-
current_app.logger.debug(f'page thumbnail {page.thumbnail_url}')
9592
return page.thumbnail_url
9693

9794
def item_thumbnail(session, id, type):
98-
current_app.logger.debug(f'Getting item thumbnail: id {id} type {type}')
9995
if type == 'page':
10096
return page_thumbnail(session, id)
10197
elif type == 'article':

scan_explorer_service/utils/s3_utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@ def write_object_s3(self, file_bytes, object_name):
2424
try:
2525
response = self.bucket.put_object(Body=file_bytes, Key=object_name)
2626
except (ClientError, ParamValidationError) as e:
27-
current_app.logger.info.exception(e)
27+
current_app.logger.exception(f"Error writing object {object_name}: {str(e)}")
2828
raise e
2929
return response.e_tag
3030

3131
def read_object_s3(self, object_name):
3232
try:
33-
current_app.logger.debug(f"Attempting to download object: {object_name}")
3433
with io.BytesIO() as s3_obj:
3534
self.bucket.download_fileobj(object_name, s3_obj)
36-
current_app.logger.debug(f"Object downloaded successfully: {object_name}")
3735
s3_obj.seek(0)
3836
s3_file = s3_obj.read()
39-
current_app.logger.debug(f"Read {len(s3_file)} bytes from object: {object_name}")
40-
current_app.logger.debug(f"First 100 bytes of file content: {s3_file[:100]}")
4137
return s3_file
4238
except Exception as e:
4339
current_app.logger.exception(f"Unexpected error reading object {object_name}: {str(e)}")

scan_explorer_service/utils/search_utils.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,44 +55,34 @@ class OrderOptions(str, enum.Enum):
5555

5656
def parse_query_args(args):
5757
qs = re.sub(':\s*', ':', args.get('q', '', str))
58-
current_app.logger.debug(f'qs {qs}')
5958

6059
qs, qs_dict = parse_query_string(qs)
6160

62-
current_app.logger.debug(f'qs {qs}, qs_dict {qs_dict}')
6361

6462

6563
page = args.get('page', 1, int)
6664
limit = args.get('limit', 10, int)
6765
sort_raw = args.get('sort')
6866
sort = parse_sorting_option(sort_raw)
69-
current_app.logger.debug(f'qs {qs}, qs_dict {qs_dict}, sort {sort}')
7067
return qs, qs_dict, page, limit, sort
7168

7269
def parse_query_string(qs):
7370
qs_to_split = qs.replace('[', '"[').replace(']',']"')
74-
current_app.logger.debug(f'qs to split {qs_to_split}')
7571
qs_arr = [q for q in shlex.split(qs_to_split) if ':' in q]
76-
current_app.logger.debug(f'qs arr {qs_arr}')
7772
qs_dict = {}
7873
qs_only_free = qs
79-
current_app.logger.debug(f'qs only free {qs_only_free}')
8074

8175
for kv in qs_arr:
8276
kv_arr = kv.split(':', maxsplit=1)
83-
current_app.logger.debug(f'kv_arr {kv_arr}')
8477
#Remove all parameter from the original search to be able to handle the free search
8578
qs_only_free = qs_only_free.replace(kv, "")
86-
current_app.logger.debug(f'qs_only_free {qs_only_free}')
8779

8880
if len(kv_arr) == 2:
8981
qs_dict[kv_arr[0].lower()] = kv_arr[1].strip()
9082
#If the option have quotes we remove them from the free. Previous removal would than have failed
9183
alt_kv = kv_arr[0] + ':"' + kv_arr[1] + '"'
9284
qs_only_free = qs_only_free.replace(alt_kv, '')
93-
current_app.logger.debug(f'kv_arr == 2. alt_kv {alt_kv}, qs_only_free {qs_only_free}')
9485

95-
current_app.logger.debug(f'qs dict {qs_dict}')
9686
check_query(qs_dict)
9787
#Adds a () around each free search to force OS to look for each individual entry against all default fields
9888
for parameter in re.split('\s+', qs_only_free):
@@ -106,7 +96,6 @@ def parse_query_string(qs):
10696
# To ensure only the strings after the colon are replaced and no partial replacements are made
10797
insensitive_replace = re.compile(r'(?<=:)\b' + re.escape(qs_dict[key]) + r'\b', re.IGNORECASE)
10898
qs = insensitive_replace.sub(qs_dict[key], qs)
109-
current_app.logger.debug(f'qs: {qs} and qs dict: {qs_dict}')
11099
return qs, qs_dict
111100

112101
def parse_sorting_option(sort_input: str):
@@ -146,14 +135,12 @@ def check_page_color(qs_dict: dict):
146135
page_color = qs_dict[SearchOptions.PageColor.value]
147136
valid_types = [p.name for p in PageColor]
148137
if page_color in valid_types:
149-
current_app.logger.debug("Page color {page_color} is valid")
150138
return
151139

152140
# Check lowercased and updated to cased
153141
for p in PageColor:
154142
if page_color.replace('"','').lower() == p.name.lower():
155143
qs_dict[SearchOptions.PageColor.value] = p.name
156-
current_app.logger.debug("Page color {qs_dict[SearchOptions.PageColor.value]} changed to {p.name}")
157144
return
158145
raise Exception("%s is not a valid page color, %s is possible choices"% (page_color, str(valid_types)))
159146

scan_explorer_service/views/image_proxy.py

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
from scan_explorer_service.utils.utils import url_for_proxy
1212
import re
1313
import io
14-
import cProfile
15-
import pstats
1614
import sys
1715

1816
bp_proxy = Blueprint('proxy', __name__, url_prefix='/image')
@@ -29,14 +27,8 @@ def image_proxy(path):
2927
req_headers['X-Forwarded-Path'] = current_app.config.get('PROXY_PREFIX').rstrip('/') + '/image'
3028

3129
encoded_url = re.sub(r"[+&]", "%2B", req_url)
32-
33-
current_app.logger.debug(f'req_url: {encoded_url}, params: {request.args}, headers: {req_headers}, data: {request.form}')
34-
3530
r = requests.request(request.method, encoded_url, params=request.args, stream=True,
36-
headers=req_headers, allow_redirects=False, data=request.form)
37-
38-
current_app.logger.debug(f"Response status code: {r.status_code}")
39-
31+
headers=req_headers, allow_redirects=False, data=request.form)
4032
excluded_headers = ['content-encoding','content-length', 'transfer-encoding', 'connection']
4133
headers = [(name, value) for (name, value) in r.headers.items() if name.lower() not in excluded_headers]
4234

@@ -53,23 +45,15 @@ def image_proxy_thumbnail():
5345
"""Helper to generate the correct url for a thumbnail given an ID and type"""
5446
try:
5547
id = request.args.get('id').replace(" ", "+")
56-
current_app.logger.debug(f'id {id}')
5748
type = request.args.get('type')
58-
current_app.logger.debug(f'type {type}')
5949

6050
with current_app.session_scope() as session:
61-
thumbnail_path = item_thumbnail(session, id, type)
62-
63-
current_app.logger.debug(f'thumbnail path {thumbnail_path}')
64-
51+
thumbnail_path = item_thumbnail(session, id, type)
6552
path = urlparse.urlparse(thumbnail_path).path
66-
current_app.logger.debug(f'path {path}')
6753

6854
remove = urlparse.urlparse(url_for_proxy('proxy.image_proxy', path='')).path
69-
current_app.logger.debug(f'remove {remove}')
7055

7156
path = path.replace(remove, '')
72-
current_app.logger.debug(f'replace {path}')
7357

7458
return image_proxy(path)
7559
except Exception as e:
@@ -81,10 +65,8 @@ def get_item(session, id):
8165
session.query(Article).filter(Article.id == id).one_or_none()
8266
or session.query(Collection).filter(Collection.id == id).one_or_none())
8367
if not item:
84-
current_app.logger.debug(f'Item with id {id} not found')
8568
raise Exception("ID: " + id + " not found")
8669

87-
current_app.logger.debug(f'Item retrieved successfully {item}')
8870
return item
8971

9072

@@ -98,7 +80,6 @@ def get_pages(item, session, page_start, page_end, page_limit):
9880
query = session.query(Page).filter(Page.collection_id == item.id,
9981
Page.volume_running_page_num >= page_start,
10082
Page.volume_running_page_num <= page_end).order_by(Page.volume_running_page_num).limit(page_limit)
101-
current_app.logger.info(f"Got pages {page_start}-{page_end}: {query}")
10283
return query
10384

10485

@@ -112,7 +93,6 @@ def fetch_images(session, item, page_start, page_end, page_limit, memory_limit):
11293
n_pages += 1
11394

11495
current_app.logger.debug(f"Generating image for page: {n_pages}")
115-
current_app.logger.debug(f'Id: {page.id}, Volume_page: {page.volume_running_page_num}, memory: {memory_sum}')
11696
if n_pages > page_limit:
11797
break
11898
if memory_sum > memory_limit:
@@ -122,37 +102,28 @@ def fetch_images(session, item, page_start, page_end, page_limit, memory_limit):
122102
object_name = '/'.join(image_path)
123103
object_name += format
124104

125-
current_app.logger.debug(f"Image path: {object_name}")
126105
im_data = fetch_object(object_name, 'AWS_BUCKET_NAME_IMAGE')
127106
memory_sum += sys.getsizeof(im_data)
128107

129108
yield im_data
130109

131110

132111
def fetch_object(object_name, bucket_name):
133-
current_app.logger.debug(f"Using bucket: {bucket_name}")
134112
file_content = S3Provider(current_app.config, bucket_name).read_object_s3(object_name)
135-
current_app.logger.debug(f"File content type: {type(file_content)}, length: {len(file_content) if file_content else 'None'}")
136113
if not file_content:
137114
current_app.logger.error(f"Failed to fetch content for {object_name}. File might be empty.")
138115
raise ValueError(f"File content is empty for {object_name}")
139-
current_app.logger.debug(f"Successfully fetched object from S3 bucket: {object_name}")
140116

141117
return file_content
142118

143119

144120
def fetch_article(item, memory_limit):
145121
try:
146-
current_app.logger.debug(f"Item is an article: {item.id}")
147-
148122
object_name = f'{item.id}.pdf'.lower()
149-
current_app.logger.debug(f"object name: {object_name}")
150123

151124
full_path = f'pdfs/{object_name}'
152-
current_app.logger.debug(f"full path: {full_path}")
153125

154126
file_content = fetch_object(full_path, 'AWS_BUCKET_NAME_PDF')
155-
current_app.logger.debug(f"File content type in fetch_article: {type(file_content)}, length: {len(file_content) if file_content else 'None'}")
156127

157128
if len(file_content) > memory_limit:
158129
current_app.logger.error(f"Memory limit reached: {len(file_content)} > {memory_limit}")
@@ -173,8 +144,6 @@ def fetch_article(item, memory_limit):
173144
def generate_pdf(item, session, page_start, page_end, page_limit, memory_limit):
174145
if isinstance(item, Article):
175146
response = fetch_article(item, memory_limit)
176-
current_app.logger.debug(f"Item is an article")
177-
current_app.logger.debug(f"response fetch article: {response}")
178147
if response:
179148
return response
180149
else:
@@ -189,38 +158,18 @@ def generate_pdf(item, session, page_start, page_end, page_limit, memory_limit):
189158
def pdf_save():
190159
"""Generate a PDF from pages"""
191160
try:
192-
profiler = cProfile.Profile()
193-
profiler.enable()
194-
195-
196161
id = request.args.get('id')
197162
page_start = request.args.get('page_start', 1, int)
198163
page_end = request.args.get('page_end', math.inf, int)
199164
memory_limit = current_app.config.get("IMAGE_PDF_MEMORY_LIMIT")
200165
page_limit = current_app.config.get("IMAGE_PDF_PAGE_LIMIT")
201166

202-
current_app.logger.debug(f"pdf ID: {id}, page_start: {page_start}, page_end: {page_end}, memory_limit: {memory_limit}, page_limit: {page_limit}")
203-
204167
with current_app.session_scope() as session:
205168

206169
item = get_item(session, id)
207170
current_app.logger.debug(f"Item retrieved successfully: {item.id}")
208171

209172
response = generate_pdf(item, session, page_start, page_end, page_limit, memory_limit)
210-
current_app.logger.debug(f"Response pdf save: {response}")
211-
212-
profiler.disable()
213-
214-
# Log the profiling information
215-
log_buffer = io.StringIO()
216-
profiler_stats = pstats.Stats(profiler, stream=log_buffer)
217-
profiler_stats.strip_dirs().sort_stats('cumulative', 'calls').print_stats(20)
218-
219-
formatted_stats = log_buffer.getvalue().splitlines()
220-
221-
current_app.logger.debug(f'==================Profiling information========================: \n')
222-
for line in formatted_stats:
223-
current_app.logger.debug(line)
224173

225174
return response
226175
except Exception as e:

0 commit comments

Comments
 (0)