sunholo 0.134.7__py3-none-any.whl → 0.135.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sunholo/custom_logging.py +101 -4
- sunholo/discovery_engine/discovery_engine_client.py +3 -2
- {sunholo-0.134.7.dist-info → sunholo-0.135.0.dist-info}/METADATA +1 -1
- {sunholo-0.134.7.dist-info → sunholo-0.135.0.dist-info}/RECORD +8 -8
- {sunholo-0.134.7.dist-info → sunholo-0.135.0.dist-info}/WHEEL +1 -1
- {sunholo-0.134.7.dist-info → sunholo-0.135.0.dist-info}/entry_points.txt +0 -0
- {sunholo-0.134.7.dist-info → sunholo-0.135.0.dist-info}/licenses/LICENSE.txt +0 -0
- {sunholo-0.134.7.dist-info → sunholo-0.135.0.dist-info}/top_level.txt +0 -0
sunholo/custom_logging.py
CHANGED
@@ -22,6 +22,8 @@ from .utils.version import sunholo_version
|
|
22
22
|
import logging
|
23
23
|
import inspect
|
24
24
|
import os
|
25
|
+
import json
|
26
|
+
from functools import wraps
|
25
27
|
|
26
28
|
class GoogleCloudLogging:
|
27
29
|
|
@@ -270,6 +272,91 @@ class GoogleCloudLogging:
|
|
270
272
|
"""
|
271
273
|
self.structured_log(log_text=log_text, log_struct=log_struct, severity="CRITICAL")
|
272
274
|
|
275
|
+
class StandardLoggerWrapper:
|
276
|
+
"""
|
277
|
+
A wrapper for standard Python logger that mimics the interface of GoogleCloudLogging.
|
278
|
+
"""
|
279
|
+
def __init__(self, logger):
|
280
|
+
self.logger = logger
|
281
|
+
self.trace_id = None
|
282
|
+
self.version = None
|
283
|
+
|
284
|
+
def _format_message(self, log_text=None, log_struct=None, severity=None):
|
285
|
+
"""Format message to include structured data as JSON"""
|
286
|
+
parts = []
|
287
|
+
|
288
|
+
# Add severity if provided
|
289
|
+
if severity:
|
290
|
+
parts.append(f"[{severity}]")
|
291
|
+
|
292
|
+
# Add trace ID if available
|
293
|
+
if self.trace_id:
|
294
|
+
parts.append(f"[trace_id:{self.trace_id}]")
|
295
|
+
|
296
|
+
# Add version if available
|
297
|
+
if self.version:
|
298
|
+
parts.append(f"[version:{self.version}]")
|
299
|
+
|
300
|
+
# Add the log text if provided
|
301
|
+
if log_text:
|
302
|
+
parts.append(log_text)
|
303
|
+
|
304
|
+
# Add structured data as JSON if provided
|
305
|
+
if log_struct:
|
306
|
+
if self.trace_id and isinstance(log_struct, dict):
|
307
|
+
log_struct["trace_id"] = self.trace_id
|
308
|
+
if self.version and isinstance(log_struct, dict):
|
309
|
+
log_struct["version"] = self.version
|
310
|
+
parts.append(f"STRUCT: {json.dumps(log_struct, default=str)}")
|
311
|
+
|
312
|
+
return " ".join(parts)
|
313
|
+
|
314
|
+
def update_trace_id(self, trace_id):
|
315
|
+
"""Set trace ID to be included in all logs."""
|
316
|
+
self.trace_id = trace_id
|
317
|
+
|
318
|
+
def set_version(self, version):
|
319
|
+
"""Set version to be included in all logs."""
|
320
|
+
self.version = version
|
321
|
+
|
322
|
+
def structured_log(self, log_text=None, log_struct=None, logger_name=None, severity="INFO"):
|
323
|
+
"""
|
324
|
+
Emulates Google Cloud's structured_log method using standard logging.
|
325
|
+
"""
|
326
|
+
message = self._format_message(log_text, log_struct, severity)
|
327
|
+
|
328
|
+
if severity == "DEBUG":
|
329
|
+
self.logger.debug(message)
|
330
|
+
elif severity == "INFO":
|
331
|
+
self.logger.info(message)
|
332
|
+
elif severity == "WARNING":
|
333
|
+
self.logger.warning(message)
|
334
|
+
elif severity == "ERROR":
|
335
|
+
self.logger.error(message)
|
336
|
+
elif severity == "CRITICAL":
|
337
|
+
self.logger.critical(message)
|
338
|
+
else:
|
339
|
+
self.logger.info(message) # Default to info
|
340
|
+
|
341
|
+
def debug(self, log_text=None, log_struct=None):
|
342
|
+
self.structured_log(log_text=log_text, log_struct=log_struct, severity="DEBUG")
|
343
|
+
|
344
|
+
def info(self, log_text=None, log_struct=None):
|
345
|
+
self.structured_log(log_text=log_text, log_struct=log_struct, severity="INFO")
|
346
|
+
|
347
|
+
def warning(self, log_text=None, log_struct=None):
|
348
|
+
self.structured_log(log_text=log_text, log_struct=log_struct, severity="WARNING")
|
349
|
+
|
350
|
+
def error(self, log_text=None, log_struct=None):
|
351
|
+
self.structured_log(log_text=log_text, log_struct=log_struct, severity="ERROR")
|
352
|
+
|
353
|
+
def exception(self, log_text=None, log_struct=None):
|
354
|
+
self.structured_log(log_text=log_text, log_struct=log_struct, severity="CRITICAL")
|
355
|
+
|
356
|
+
# Forward any other standard logging methods to the underlying logger
|
357
|
+
def __getattr__(self, name):
|
358
|
+
return getattr(self.logger, name)
|
359
|
+
|
273
360
|
def is_logging_setup(logger=None):
|
274
361
|
logger = logger or logging.getLogger() # If no logger is specified, use the root logger
|
275
362
|
return bool(logger.handlers)
|
@@ -352,7 +439,14 @@ def setup_logging(logger_name=None, log_level=logging.INFO, project_id=None):
|
|
352
439
|
|
353
440
|
logger = logging.getLogger(logger_name)
|
354
441
|
if is_logging_setup(logger):
|
355
|
-
|
442
|
+
# Check if it's already our wrapper
|
443
|
+
if hasattr(logger, 'structured_log'):
|
444
|
+
return logger
|
445
|
+
else:
|
446
|
+
# Wrap the existing logger
|
447
|
+
wrapper = StandardLoggerWrapper(logger)
|
448
|
+
wrapper.set_version(sunholo_version())
|
449
|
+
return wrapper
|
356
450
|
|
357
451
|
if logger_name is None:
|
358
452
|
logger_name = "sunholo"
|
@@ -370,10 +464,13 @@ def setup_logging(logger_name=None, log_level=logging.INFO, project_id=None):
|
|
370
464
|
return gc_logger.setup_logging()
|
371
465
|
else:
|
372
466
|
if not logging.getLogger().hasHandlers():
|
373
|
-
logging.basicConfig(level=
|
467
|
+
logging.basicConfig(level=log_level, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
374
468
|
log = logging.getLogger(logger_name)
|
375
|
-
|
376
|
-
|
469
|
+
|
470
|
+
# Wrap the standard logger to support log_struct parameter
|
471
|
+
wrapper = StandardLoggerWrapper(log)
|
472
|
+
wrapper.set_version(sunholo_version())
|
473
|
+
return wrapper
|
377
474
|
|
378
475
|
# for debugging
|
379
476
|
def safe_log_struct(log, severity, message, struct):
|
@@ -925,18 +925,19 @@ class DiscoveryEngineClient:
|
|
925
925
|
if parse_chunks_to_string:
|
926
926
|
if content_search_spec_type=="chunks":
|
927
927
|
if parse_chunks_to_string:
|
928
|
-
big_string = self.async_process_chunks(search_response)
|
928
|
+
big_string = await self.async_process_chunks(search_response)
|
929
929
|
log.info(f"Discovery engine chunks string sample: {big_string[:100]}")
|
930
930
|
|
931
931
|
return big_string
|
932
932
|
|
933
933
|
elif content_search_spec_type=="documents":
|
934
|
-
big_string = self.async_process_documents(search_response)
|
934
|
+
big_string = await self.async_process_documents(search_response)
|
935
935
|
log.info(f"Discovery engine documents string sample: {big_string[:100]}")
|
936
936
|
|
937
937
|
return big_string
|
938
938
|
|
939
939
|
log.info("Discovery engine response object")
|
940
|
+
|
940
941
|
return search_response
|
941
942
|
|
942
943
|
def search_by_objectId_and_or_date(self, query, objectId=None, date=None, **kwargs):
|
@@ -1,5 +1,5 @@
|
|
1
1
|
sunholo/__init__.py,sha256=InRbX4V0-qdNHo9zYH3GEye7ASLR6LX8-SMvPV4Jsaw,1212
|
2
|
-
sunholo/custom_logging.py,sha256=
|
2
|
+
sunholo/custom_logging.py,sha256=JXZTnXp_DixP3jwYfKw4LYRDS9IuTq7ctCgfZbI2rxA,22023
|
3
3
|
sunholo/langchain_types.py,sha256=uZ4zvgej_f7pLqjtu4YP7qMC_eZD5ym_5x4pyvA1Ih4,1834
|
4
4
|
sunholo/agents/__init__.py,sha256=X2I3pPkGeKWjc3d0QgSpkTyqD8J8JtrEWqwrumf1MMc,391
|
5
5
|
sunholo/agents/chat_history.py,sha256=Gph_CdlP2otYnNdR1q1Umyyyvcad2F6K3LxU5yBQ9l0,5387
|
@@ -75,7 +75,7 @@ sunholo/discovery_engine/__init__.py,sha256=hLgqRDJ22Aov9o2QjAEfsVgnL3kMdM-g5p8R
|
|
75
75
|
sunholo/discovery_engine/chunker_handler.py,sha256=wkvXl4rFtYfN6AZUKdW9_QD49Whf77BukDbO82UwlAg,7480
|
76
76
|
sunholo/discovery_engine/cli.py,sha256=tsKqNSDCEsDTz5-wuNwjttb3Xt35D97-KyyEiaqolMQ,35628
|
77
77
|
sunholo/discovery_engine/create_new.py,sha256=WUi4_xh_dFaGX3xA9jkNKZhaR6LCELjMPeRb0hyj4FU,1226
|
78
|
-
sunholo/discovery_engine/discovery_engine_client.py,sha256=
|
78
|
+
sunholo/discovery_engine/discovery_engine_client.py,sha256=Sf7Sr6FYKA_jn19Ba2ENShrB1jnZ4HgPScuytDIuK9c,58705
|
79
79
|
sunholo/discovery_engine/get_ai_search_chunks.py,sha256=I6Dt1CznqEvE7XIZ2PkLqopmjpO96iVEWJJqL5cJjOU,5554
|
80
80
|
sunholo/embedder/__init__.py,sha256=sI4N_CqgEVcrMDxXgxKp1FsfsB4FpjoXgPGkl4N_u4I,44
|
81
81
|
sunholo/embedder/embed_chunk.py,sha256=did2pKkWM2o0KkRcb0H9l2x_WjCq6OyuHDxGbITFKPM,6530
|
@@ -168,9 +168,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
|
|
168
168
|
sunholo/vertex/memory_tools.py,sha256=tBZxqVZ4InTmdBvLlOYwoSEWu4-kGquc-gxDwZCC4FA,7667
|
169
169
|
sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
|
170
170
|
sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
|
171
|
-
sunholo-0.
|
172
|
-
sunholo-0.
|
173
|
-
sunholo-0.
|
174
|
-
sunholo-0.
|
175
|
-
sunholo-0.
|
176
|
-
sunholo-0.
|
171
|
+
sunholo-0.135.0.dist-info/licenses/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
|
172
|
+
sunholo-0.135.0.dist-info/METADATA,sha256=jLaY76jTW-W8S-9V7_9THZZ3-FroKO6HHoFKvloXXPI,10067
|
173
|
+
sunholo-0.135.0.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
174
|
+
sunholo-0.135.0.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
|
175
|
+
sunholo-0.135.0.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
|
176
|
+
sunholo-0.135.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|