Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/ / /
PyMongo 드라이버
/

로깅

이 가이드 에서는 다양한 PyMongo 구성 요소에 대한 로깅 옵션을 구성하는 방법을 학습 수 있습니다.

PyMongo Python의 네이티브 로깅 라이브러리를 지원합니다. 다음 구성 요소에 대한 로깅 상세도를 구성할 수 있습니다.

  • pymongo.command, 명령 작업을 기록합니다.

  • pymongo.connection, 연결 관리 작업을 기록합니다.

  • pymongo.serverSelection, 서버 선택 작업을 기록합니다.

In addition to configuring these options individually, you can configure the global logging level by setting the log level on pymongo. To learn more about the native logging library, see the Python logging library documentation.

다음 예시 글로벌 로깅 수준을 INFO로 설정합니다.

import logging
logging.getLogger("pymongo").setLevel(logging.INFO)

다음 예시 pymongo.command 구성 요소의 로그 수준을 DEBUG로 설정합니다.

import logging
logging.getLogger("pymongo.command").setLevel(logging.DEBUG)

운전자 출력하는 메시지는 DEBUG 메시지 예시 에서 볼 수 있듯이 메시지 시작 부분에 로그 수준이 지정되어 있습니다.

DEBUG:pymongo.command:{"clientId": {"$oid": "..."}, "message": "Command started", "command": "{\"insert\": \"test\", \"ordered\": true, \"lsid\": {\"id\": {\"$binary\": {\"base64\": \"...\", \"subType\": \"04\"}}}, \"$db\": \"db\", \"documents\": [{\"x\": 1, \"_id\": {\"$oid\": \"...\"}}]}", "commandName": "insert", "databaseName": "db", "requestId": ..., "operationId": ..., "driverConnectionId": 1, "serverConnectionId": 3554, "serverHost": "localhost", "serverPort": 27017}

pymongo.command 구성 요소에 대한 로깅을 활성화 하면 기본값 으로 1000 바이트 이후 결과 로그가 잘립니다. 다음 예시 와 같이 MONGODB_LOG_MAX_DOCUMENT_LENGTH 환경 변수를 원하는 길이로 설정하여 이 잘림 제한을 구성할 수 있습니다.

import os
os.environ["MONGODB_LOG_MAX_DOCUMENT_LENGTH"] = "2000"

돌아가기

모니터링

이 페이지의 내용