macOS Error, Fault 로그를 CSV 파일로 출력
10083 단어 ShellScriptMac
개요
이 문서에서는 log 명령을 사용하여 macOS의 Error, Fault 로그를 추출하고 CSV 파일에 로그를 출력하는 명령을 작성합니다. 또한 당일 발생한 Error, Fault 로그만 CSV에 출력하는 쉘 스크립트를 작성합니다.
운영 환경
macOS Catalina (MacBookAir2019)
1.error,Fault 로그 출력
log show
를 입력하고 Enter를 누르십시오. 명령을 실행하면 모든 로그가 출력됩니다. % log show | more
Timestamp Thread Type Activity PID TTL
2020-05-05 19:16:40.063938-0700 0x0 Timesync 0x0 0 0 === system boot: 571DA786-615F-4413-944B-1D34B63BA616
2020-05-05 19:16:40.063938-0700 0x0 Timesync 0x0 0 0 === log class: TTL more than 14 days begins
2020-05-05 19:16:40.063938-0700 0x0 Timesync 0x0 0 0 === log class: persist begins
2020-05-05 19:16:40.063980-0700 0x0 Default 0x0 0 0 kernel: mem_actual: 0x400000000
(非常に長いため省略)
log show --predicate 'messageType == "error"'
를 입력하고 Enter 키를 누릅니다. % log show --predicate 'messageType == "error"' | more
Timestamp Thread Type Activity PID TTL
2020-05-05 19:16:42.931110-0700 0x26a Error 0x0 72 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
2020-05-05 19:16:42.949256-0700 0x2bc Error 0x0 72 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
2020-05-05 19:16:42.976184-0700 0x2c1 Error 0x0 72 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
2020-05-05 19:16:42.977242-0700 0x2bf Error 0x20 102 0 tccd: (libsqlite3.dylib) [com.apple.libsqlite3:logging-persist] cannot open file at line 43353 of [378230ae7f]
(非常に長いため省略)
log show --predicate 'messageType == "fault"'
를 입력하고 Enter 키를 누릅니다. % log show --predicate 'messageType == "fault"' | more
Timestamp Thread Type Activity PID TTL
2020-05-05 19:17:29.320269-0700 0x394 Fault 0x0 0 0 kernel: (IOAcceleratorFamily2) bool IOAccelDisplayPipe::init_framebuffer_resource(IOAccelResource2 *): getPixelInformation for framebuffer 0 failed
2020-05-05 19:17:29.559630-0700 0x394 Fault 0x0 0 0 kernel: (IOAcceleratorFamily2) virtual IOReturn IOAccelLegacySurface::set_id_mode(uint32_t, uint32_t): Surface mode contains bad bits
2020-05-05 19:17:29.559788-0700 0x394 Fault 0x0 0 0 kernel: (IOAcceleratorFamily2) virtual IOReturn IOAccelLegacySurface::set_id_mode(uint32_t, uint32_t): Surface mode contains bad bits
2020-05-05 19:17:29.559875-0700 0x394 Fault 0x0 0 0 kernel: (IOAcceleratorFamily2) virtual IOReturn IOAccelLegacySurface::set_id_mode(uint32_t, uint32_t): Surface mode contains bad bits
(非常に長いため省略)
2.Error,Fault 로그를 CSV에 출력한다
% log show --predicate 'messageType == "error"'>/tmp/test2/errorlog.csv
% log show --predicate 'messageType == "fault"'>/tmp/test2/faultlog.csv
% ls -la /tmp/test2
total 57360
drwxr-xr-x 4 yuichiwest wheel 128 5 24 19:46 .
drwxrwxrwt 15 root wheel 480 5 24 19:47 ..
-rw-r--r-- 1 yuichiwest wheel 26946597 5 24 19:45 errorlog.csv
-rw-r--r-- 1 yuichiwest wheel 1497197 5 24 19:46 faultlog.csv
% cat /tmp/test2/errorlog.csv | more
Timestamp Thread Type Activity PID TTL
2020-05-05 19:16:42.931110-0700 0x26a Error 0x0 72 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
2020-05-05 19:16:42.949256-0700 0x2bc Error 0x0 72 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
2020-05-05 19:16:42.976184-0700 0x2c1 Error 0x0 72 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
2020-05-05 19:16:42.977242-0700 0x2bf Error 0x20 102 0 tccd: (libsqlite3.dylib) [com.apple.libsqlite3:logging-persist] cannot open file at line 43353 of [378230ae7f]
(省略)
% cat /tmp/test2/faultlog.csv | more
Timestamp Thread Type Activity PID TTL
2020-05-05 19:17:29.320269-0700 0x394 Fault 0x0 0 0 kernel: (IOAcceleratorFamily2) bool IOAccelDisplayPipe::init_framebuffer_resource(IOAccelResource2 *): getPixelInformation for framebuffer 0 failed
2020-05-05 19:17:29.559630-0700 0x394 Fault 0x0 0 0 kernel: (IOAcceleratorFamily2) virtual IOReturn IOAccelLegacySurface::set_id_mode(uint32_t, uint32_t): Surface mode contains bad bits
2020-05-05 19:17:29.559788-0700 0x394 Fault 0x0 0 0 kernel: (IOAcceleratorFamily2) virtual IOReturn IOAccelLegacySurface::set_id_mode(uint32_t, uint32_t): Surface mode contains bad bits
2020-05-05 19:17:29.559875-0700 0x394 Fault 0x0 0 0 kernel: (IOAcceleratorFamily2) virtual IOReturn IOAccelLegacySurface::set_id_mode(uint32_t, uint32_t): Surface mode contains bad bits
(省略)
3. 당일 발생한 Error, Fault 로그만을 출력하는 쉘 스크립트 작성
#!/bin/sh
<< COMMENTOUT
logsearch(macOS)
Copyright (c) 2020 yuichi1992_west
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
COMMENTOUT
# Get today's date
log_date=`date +"%Y-%m-%d"`
# Specify the log storage location
log_space='/tmp/test3'
# Output error log
log show --predicate 'messageType == "error"' | grep "${log_date}" > "${log_space}"/error_log_"${log_date}".csv
# Output fault log
log show --predicate 'messageType == "fault"' | grep "${log_date}" > "${log_space}"/fault_log_"${log_date}".csv
exit 0
% bash logsearch.sh
% ls -la /tmp/test3
total 6656
drwxr-xr-x 4 yuichiwest wheel 128 5 24 20:09 .
drwxrwxrwt 18 root wheel 576 5 24 20:15 ..
-rw-r--r-- 1 yuichiwest wheel 2928838 5 24 20:09 error_log_2020-05-24.csv
-rw-r--r-- 1 yuichiwest wheel 137697 5 24 20:10 fault_log_2020-05-24.csv
% cat /tmp/test3/error_log_2020-05-24.csv | more
2020-05-24 10:08:52.588855+0900 0x31a Error 0x0 139 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
2020-05-24 10:08:52.742746+0900 0x32f Error 0x0 139 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
2020-05-24 10:08:52.744104+0900 0x2c4 Error 0x0 151 0 displaypolicyd: (CoreFoundation) [com.apple.defaults:User Defaults] All kCFPreferencesCurrentUser domains in this process will be volatile, because homeDirPath starts with /var/empty
2020-05-24 10:08:52.745015+0900 0x32f Error 0x0 139 0 opendirectoryd: [com.apple.opendirectoryd:default] Failed to open file <private> [2: No such file or directory]
(省略)
% cat /tmp/test3/fault_log_2020-05-24.csv | more
2020-05-24 10:08:53.089823+0900 0x3a3 Fault 0x190 183 14 contextstored: (CoreFoundation) [com.apple.defaults:User Defaults] Couldn't read values in CFPrefsPlistSource<0x7fe9b7707ce0> (Domain: kCFPreferencesAnyApplication, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): accessing preferences outside an application's container requires user-preference-read or file-read-data sandbox access
2020-05-24 10:08:53.090168+0900 0x3a3 Fault 0x191 183 14 contextstored: (CoreFoundation) [com.apple.defaults:User Defaults] Couldn't read values in CFPrefsPlistSource<0x7fe9b7707fb0> (Domain: kCFPreferencesAnyApplication, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: No): accessing preferences outside an application's container requires user-preference-read or file-read-data sandbox access
2020-05-24 10:08:53.277770+0900 0x43c Fault 0x1f2 183 14 contextstored: (KnowledgeMonitor) [com.apple.coreduet.knowledge:] Requested the previousEvent from instantState in setCurrentEvent, but received nil in stream: Backlight.
2020-05-24 10:08:53.278484+0900 0x43b Fault 0x1f5 183 14 contextstored: (KnowledgeMonitor) [com.apple.coreduet.knowledge:] Requested the previousEvent from instantState in setCurrentEvent, but received nil in stream: ChargerPluggedInState.
(省略)
마지막으로
macOS의 Error, Fault 로그를 출력하는 것으로, 하드웨어나 어플리케이션의 버그를 조사하는데 도움이 된다고 생각합니다. 또 CSV에 출력하는 것으로 Excel을 이용해 로그 데이터를 가공할 수 있어 로그 데이터에 의한 결함의 조사가 하기 쉬워진다고 생각합니다.
Reference
이 문제에 관하여(macOS Error, Fault 로그를 CSV 파일로 출력), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/yuichi1992_west/items/aaf8241be15922050237텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)