Lors d'une revue de code Java, j'ai trouvé cette partie intéressante :
log.debug(message, new Exception("DEBUGGING STACK TRACE"));
Elle affichera une ligne de DEBUG et son contexte dans la foulée. Ce qui peut être très pratique.
Exemple :
[0-exec-10] [S3_Download] Read s3://my-test-bucket/my-key (62204 bytes) in 0.152 s
java.lang.Exception: DEBUGGING STACK TRACE
at org.nuxeo.ecm.blob.s3.S3BlobStore.readBlob(S3BlobStore.java:462)
at org.nuxeo.ecm.core.blob.LocalBlobStore.copyBlobGeneric(LocalBlobStore.java:160)
at org.nuxeo.ecm.core.blob.LocalBlobStore.copyOrMoveBlob(LocalBlobStore.java:102)
at org.nuxeo.ecm.core.blob.CachingBlobStore.getStream(CachingBlobStore.java:205)
at org.nuxeo.ecm.core.blob.BlobStoreBlobProvider.getStream(BlobStoreBlobProvider.java:145)
at org.nuxeo.ecm.core.blob.BlobStoreBlobProvider.getStream(BlobStoreBlobProvider.java:133)
at org.nuxeo.ecm.core.blob.ManagedBlob.getStream(ManagedBlob.java:60)
at org.nuxeo.ecm.core.io.download.DownloadServiceImpl.transferBlobWithByteRange(DownloadServiceImpl.java:806)
at org.nuxeo.ecm.core.io.download.DownloadServiceImpl.transferBlobWithByteRange(DownloadServiceImpl.java:790)
at org.nuxeo.ecm.core.io.download.DownloadServiceImpl.lambda$downloadBlob$0(DownloadServiceImpl.java:572)
at org.nuxeo.ecm.core.io.download.DownloadServiceImpl.downloadBlob(DownloadServiceImpl.java:744)
...
J'ai aussitôt voulu faire la même chose en Python.
En parcourant le code source de CPython puis la documentation du module logging, j'ai trouvé le bon argument à utiliser :
log.debug(message, stack_info=True)
Ce qui donnera :
2021-02-20 14:48:36 32411 123145400360960 DEBUG nxdrive.client.uploader Chunk uploaded @ 8 MiB/s [20.0% done]
Stack (most recent call last):
File "engine/workers.py", line 196, in run
self._execute()
File "engine/processor.py", line 317, in _execute
self._handle_doc_pair_sync(doc_pair, sync_handler)
File "engine/processor.py", line 240, in _handle_doc_pair_sync
sync_handler(doc_pair)
File "engine/processor.py", line 949, in _synchronize_locally_created
fs_item_info = self.remote.stream_file(
File "client/remote_client.py", line 582, in stream_file
fs_item = self.upload(
File "client/remote_client.py", line 446, in upload
return uploader(self).upload(path, **kwargs)
File "client/uploader/sync.py", line 31, in upload
item = self.upload_impl(file_path, command, filename=filename, **kwargs)
File "client/uploader/__init__.py", line 206, in upload_impl
self.upload_chunks(transfer, blob, chunked)
File "client/uploader/__init__.py", line 295, in upload_chunks
log.debug(message, stack_info=True)