'calling `log stream --predicate` command via `subprocess` does not append logs to stdout
I’m writing a python script which calls the below commmand via subprocess and stores the logs to output.txt for further parsing
log stream --level debug --predicate 'subsystem contains "com.apple.UVCExtension" and composedMessage contains "Post PowerLog"'
when I execute this command in the terminal, the logs stream produces output like below
Filtering the log data using "subsystem CONTAINS "com.apple.UVCExtension" AND composedMessage CONTAINS "Post PowerLog""
Timestamp Thread Type Activity PID TTL
2022-02-17 17:07:51.336951+0530 0xbb0f0 Default 0x0 369 0 UVCAssistant: (UVCExtension) [com.apple.UVCExtension:device] UVCExtensionAppleDevice:0x1000005fe [0x7f8sffea0he80] Post PowerLog {
"VDCAssistant_Device_GUID" = "XXXXX";
"VDCAssistant_Power_State" = On;
}
2022-02-17 17:07:52.241387+0530 0xbb0f0 Default 0x0 369 0 UVCAssistant: (UVCExtension) [com.apple.UVCExtension:device] UVCExtensionAppleDevice:0x1000004ty [sdg4566679e80] Post PowerLog {
"VDCAssistant_Device_GUID" = "XXXX";
"VDCAssistant_Power_State" = Off;
}
However while calling the same command via subprocess, I'm unable to see any of the log values. I just see the first line of output. I want to parse the "ON" "Off" status of VDCassistant.
This is my python code
import subprocess
from threading import Thread
from time import sleep
def func1():
f = open("output.txt", "w")
subprocess.call(['log', 'stream','--style', 'json' , '--predicate', '(subsystem contains "com.ale.UVCExtension") and (composedMessage contains "Post PowerLog")'], stdout=f, stderr=f)
return f
def func2():
while True:
sleep(5)
with open("output.txt", "r") as file:
result = (list(file))
print(result)
if "On;" in result:
print (On status)
else:
print ("Off status")
if __name__ == '__main__':
Thread(target = func1).start()
Thread(target = func2).start()
What is going wrong here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
