Superskyyy commented on code in PR #323:
URL: https://github.com/apache/skywalking-python/pull/323#discussion_r1361242292
##########
skywalking/loggings.py:
##########
@@ -22,12 +22,21 @@
logger_debug_enabled = False
+class SWFilter(logging.Filter):
+ def filter(self, record):
+ from skywalking.trace.context import get_context
+ context = get_context()
+ record.tid = str(context.segment.related_traces[0])
+ return True
+
+
def getLogger(name=None): # noqa
logger = logging.getLogger(name)
ch = logging.StreamHandler()
- formatter = logging.Formatter('%(asctime)s %(name)s [pid:%(process)d]
[%(threadName)s] [%(levelname)s] %(message)s')
+ formatter = logging.Formatter('%(asctime)s %(name)s %(tid)s
[pid:%(process)d] [%(threadName)s] [%(levelname)s] %(message)s')
Review Comment:
This feature should be optional as consistent with the Java agent (see
[here](https://skywalking.apache.org/docs/skywalking-java/next/en/setup/service-agent/java-agent/application-toolkit-logback-1.x/#print-trace-id-in-your-logs)),
because not all users want tids in their logs. To achieve this behavior in
Python, please introduce a new setting to control the insertion of tids and
adding the additional filter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]