AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

getLog (데이터베이스 명령)

getLog

getLogmongod또는mongos인스턴스 에 대해 가장 최근에 기록된 1024 이벤트를 반환하는 관리 명령입니다. getLog은 (로그 파일 에서 로그 데이터를 읽지 않습니다. 대신mongod또는mongos에서 기록된 이벤트의 RAM 캐시 에서 데이터를 읽습니다. getLog를 실행 하려면db.adminCommand()메서드를 사용합니다.

는 이스케이프 처리된 Relaxed2 0 getLog Extended JSON v. 형식으로 로그 데이터를 반환합니다. 이전에는 로그 데이터가 일반 텍스트로 반환되었습니다.

이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

참고

이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.

명령은 다음과 같은 구문을 가집니다:

db.adminCommand(
{
getLog: <value>
}
)

에 사용할 수 있는 값은 다음과 getLog 같습니다.

설명

*

명령에 getLog 사용 가능한 값 목록을 반환합니다.

global

모든 최근 로그 항목의 합산 출력을 반환합니다.

startupWarnings

현재 프로세스 시작되었을 때 MongoDB 로그 의 오류 또는 경고가 포함될 수 있는 로그 항목을 반환합니다. 프로세스 경고 없이 시작된 경우 이 필터하다 빈 배열 반환할 수 있습니다.

참고

이 메시지 유형 분류는 더 이상 getLog 사용되지 않으므로 명령은 더 이상 값을 허용하지 않습니다.rs 대신 이제 로그 메시지는 복제 메시지의 경우 REPL을 포함하여 항상 해당 구성 요소로 식별됩니다. 구성 필드 를 필터하다 하는 로그 구문 분석 예제는 구성 요소별 필터링을 참조하세요.

*로 지정하면 명령은 허용되는 다른 값의 이름이 포함된 문서를 반환합니다.

그렇지 않으면 명령은 다음 필드를 포함하는 문서를 반환합니다.

  • totalLinesWritten 로그 이벤트 수가 포함된 필드입니다.

  • log 로그 이벤트 배열을 포함하는 필드

  • 상태 및 타임스탬프 정보가 포함된 db.adminCommand() 응답 문서입니다.

getLog 1024자를 초과하는 모든 이벤트를 잘라냅니다.

getLog는 다음 이스케이프 시퀀스2 0 로그 로그 을 유효한 JSON JSON 렌더링합니다.

대체 문자
시퀀스 이스케이프

따옴표 (")

\"

백슬래시 (\)

\\

백스페이스 (0x08)

\b

폼피드 (0x0C)

\f

뉴라인 (0x0A)

\n

캐리지 리턴 (0x0D)

\r

가로 탭 (0x09)

\t

위에 나열되지 않은 제어 문자는 \uXXXX로 이스케이프됩니다. 여기서 " XXXX " 는 16진수의 유니코드 코드 포인트입니다. 잘못된 UTF-8 인코딩이 있는 바이트는 \ufffd로 표시되는 유니코드 대체 문자로 대체됩니다.

getLog 출력을 필터링하여 결과를 더 읽기 쉽게 만들거나 특정 기준에 일치시킬 수 있습니다.

다음 작업은 log 필드(모든 최근 로그 이벤트의 배열 포함)만 출력하고 각 로그 메시지에서 이스케이프 문자를 제거합니다.

db.adminCommand( { getLog:'global'} ).log.forEach(x => {print(x)})

이 작업은 출력을 MongoDB getLog log file동일한 형식으로 표시합니다.

참고

getLog는 가장 최근에 기록된 1024 이벤트만 표시하며 MongoDB 를 대체하지 log file 않습니다.

MongoDB 구조화된 로깅 작업 시 타사 jq 명령줄 유틸리티를 사용하여 로그 항목을 가독성 있게 간편하게 출력하고 강력한 키 기반 매칭 및 필터링을 수행할 수 있습니다.

jq 는 오픈 소스 JSON 파서이며 Linux, Windows, macOS에서 사용할 수 있습니다.

jq getLog 출력과 함께 을 사용하려면 --eval mongosh에 대해 옵션을 사용해야 합니다. 다음 작업은 를 사용하여 jq REPL 구성 요소를 필터하다 하여 복제 와 관련된 로그 메시지만 표시합니다.

mongosh --quiet --eval "db.adminCommand( { getLog:'global'} ).log.forEach(x => {print(x)})" | jq -c '. | select(.c=="REPL")'

또는 와 mongosh --host 같이 필요에 따라 에 필요한 연결별 매개변수를 제공해야 --port 합니다.

를 사용하여 로그 출력을 필터링하는 더 많은 예는 구조화된 로그 메시지 구문 분석을 참조하세요.jq jq 링크된 각 예시 에 제시된 구문은 약간의 조정을 통해 위의 작업과 함께 사용할 수 mongo --eval 있습니다. 예시 들어, 다음 구문은 링크된 "Counting Unique Messages&" 와 함께 사용하는 예시 getLog:

mongosh --quiet --eval "db.adminCommand( { getLog:'global'} ).log.forEach(x => {print(x)})" | jq -r ".msg" | sort | uniq -c | sort -rn | head -10

getLog에서 실행 mongosh다음 작업은 에 전달하는 데 사용 가능한 로그 필터를 반환합니다.

db.adminCommand( { getLog: "*" } )

연산은 다음 문서를 반환합니다.

{ "names" : [ "global", "startupWarnings" ], "ok" : 1 }

에서 실행 다음 작업은 mongosh 또는 global 인스턴스 에 대한 mongod 가장 최근의 mongos 이벤트를 검색합니다.

db.adminCommand( { getLog : "global" } )

이 작업은 다음과 유사한 문서를 반환합니다.

{
"totalLinesWritten" : <num>,
"log" : [
"{\"t\":{\"$date\":\"2020-05-19T19:10:48.871+00:00\"},\"s\":\"I\", \"c\":\"STORAGE\", \"id\":4615611, \"ctx\":\"initandlisten\",\"msg\":\"MongoDB starting\",\"attr\":{\"pid\":12345,\"port\":27001,\"dbPath\":\"/var/lib/mongo\",\"architecture\":\"64-bit\",\"host\":\"server1.example.com\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:48.871+00:00\"},\"s\":\"I\", \"c\":\"CONTROL\", \"id\":23403, \"ctx\":\"initandlisten\",\"msg\":\"Build Info\",\"attr\":{\"buildInfo\":{\"version\":\"4.4.0\",\"gitVersion\":\"328c35e4b883540675fb4b626c53a08f74e43cf0\",\"openSSLVersion\":\"OpenSSL 1.1.1c FIPS 28 May 2019\",\"modules\":[],\"allocator\":\"tcmalloc\",\"environment\":{\"distmod\":\"rhel80\",\"distarch\":\"x86_64\",\"target_arch\":\"x86_64\"}}}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:48.871+00:00\"},\"s\":\"I\", \"c\":\"CONTROL\", \"id\":51765, \"ctx\":\"initandlisten\",\"msg\":\"Operating System\",\"attr\":{\"os\":{\"name\":\"CentOS Linux release 8.0.1905 (Core) \",\"version\":\"Kernel 4.18.0-80.11.2.el8_0.x86_64\"}}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:48.871+00:00\"},\"s\":\"I\", \"c\":\"CONTROL\", \"id\":21951, \"ctx\":\"initandlisten\",\"msg\":\"Options set by command line\",\"attr\":{\"options\":{\"config\":\"/etc/mongod.conf\",\"net\":{\"bindIp\":\"127.0.0.1\",\"port\":27001},\"processManagement\":{\"fork\":true,\"timeZoneInfo\":\"/usr/share/zoneinfo\"},\"replication\":{\"replSetName\":\"repl-shard1\"},\"sharding\":{\"clusterRole\":\"shardsvr\"},\"storage\":{\"dbPath\":\"/var/lib/mongo\",\"journal\":{\"enabled\":true},\"wiredTiger\":{\"engineConfig\":{\"cacheSizeGB\":0.1}}},\"systemLog\":{\"destination\":\"file\",\"logAppend\":true,\"path\":\"/var/log/mongodb/mongod.log\"}}}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:48.873+00:00\"},\"s\":\"I\", \"c\":\"STORAGE\", \"id\":22270, \"ctx\":\"initandlisten\",\"msg\":\"Storage engine to use detected by data files\",\"attr\":{\"dbpath\":\"/var/lib/mongo\",\"storageEngine\":\"wiredTiger\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:48.873+00:00\"},\"s\":\"I\", \"c\":\"STORAGE\", \"id\":22315, \"ctx\":\"initandlisten\",\"msg\":\"wiredtiger_open config\",\"attr\":{\"config\":\"create,cache_size=102M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"CONNPOOL\", \"id\":22576, \"ctx\":\"ReplicaSetMonitor-TaskExecutor\",\"msg\":\"Connecting\",\"attr\":{\"hostAndPort\":\"server1.example.com:27001\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"CONNPOOL\", \"id\":22576, \"ctx\":\"ReplicaSetMonitor-TaskExecutor\",\"msg\":\"Connecting\",\"attr\":{\"hostAndPort\":\"server2.example.com:27001\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"CONNPOOL\", \"id\":22576, \"ctx\":\"ReplicaSetMonitor-TaskExecutor\",\"msg\":\"Connecting\",\"attr\":{\"hostAndPort\":\"server3.example.com:27001\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"CONNPOOL\", \"id\":22576, \"ctx\":\"ReplicaSetMonitor-TaskExecutor\",\"msg\":\"Connecting\",\"attr\":{\"hostAndPort\":\"server4.example.com:27001\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"CONNPOOL\", \"id\":22576, \"ctx\":\"ReplicaSetMonitor-TaskExecutor\",\"msg\":\"Connecting\",\"attr\":{\"hostAndPort\":\"server5.example.com:27001\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"CONNPOOL\", \"id\":22576, \"ctx\":\"ReplicaSetMonitor-TaskExecutor\",\"msg\":\"Connecting\",\"attr\":{\"hostAndPort\":\"server6.example.com:27001\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"NETWORK\", \"id\":23015, \"ctx\":\"listener\",\"msg\":\"Listening on\",\"attr\":{\"address\":\"/tmp/mongodb-27001.sock\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"NETWORK\", \"id\":23015, \"ctx\":\"listener\",\"msg\":\"Listening on\",\"attr\":{\"address\":\"127.0.0.1\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:10:58.877+00:00\"},\"s\":\"I\", \"c\":\"NETWORK\", \"id\":23016, \"ctx\":\"listener\",\"msg\":\"Waiting for connections\",\"attr\":{\"port\":27001,\"ssl\":\"off\"}}",
"{\"t\":{\"$date\":\"2020-05-19T19:15:10.392+00:00\"},\"s\":\"I\", \"c\":\"NETWORK\", \"id\":22943, \"ctx\":\"listener\",\"msg\":\"connection accepted\",\"attr\":{\"remote\":\"127.0.0.1:35724\",\"sessionId\":67,\"connectionCount\":30}}",
"{\"t\":{\"$date\":\"2020-05-19T19:15:10.393+00:00\"},\"s\":\"I\", \"c\":\"NETWORK\", \"id\":51800, \"ctx\":\"conn67\",\"msg\":\"client metadata\",\"attr\":{\"remote\":\"127.0.0.1:35724\",\"client\":\"conn67\",\"doc\":{\"application\":{\"name\":\"MongoDB Shell\"},\"driver\":{\"name\":\"MongoDB Internal Client\",\"version\":\"4.4.0\"},\"os\":{\"type\":\"Linux\",\"name\":\"CentOS Linux release 8.0.1905 (Core) \",\"architecture\":\"x86_64\",\"version\":\"Kernel 4.18.0-80.11.2.el8_0.x86_64\"}}}}"
],
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(<ts>),
"electionId" : ObjectId(<id>)
},
"lastCommittedOpTime" : Timestamp(<ts>),
"$configServerState" : {
"opTime" : {
"ts" : Timestamp(<ts>),
"t" : Long(8)
}
},
"$clusterTime" : {
"clusterTime" : Timestamp(<ts>),
"signature" : {
"hash" : BinData(<bin>),
"keyId" : Long(0)
}
},
"operationTime" : Timestamp(<ts>)
}