How can I direct messages from mac console.app to a log file?


 
Thread Tools Search this Thread
Operating Systems OS X (Apple) How can I direct messages from mac console.app to a log file?
# 1  
Old 09-03-2019
How can I direct messages from mac console.app to a log file?

I'm trying to complete a bash script to capture if an external webcam is active in a video conference session. Some users will switch the camera to the built-in MAC camera. When this happens I want to trigger a set of events.

Things tried: reviewed the console.app to look for patterns on when the switch occurs in a user test & discovered messages indicating when the facetime camera changes state. I found this

Code:
019-08-31 22:59:57.387405 -0500 AppleCameraInterface default 0 22:59:57.387405 -0500 kernel AppleCamIn::power_on_hardware

2019-08-31 22:59:57.814936 -0500 AppleCameraAssistant default 438 22:59:57.814936 -0500 AppleCameraAssistant StartHardwareStream: creating frame receiver: 1280 x 720 (420v) [12.00,30.00]fps

2019-08-31 22:59:59.679037 -0500 AppleCameraAssistant default 438 22:59:59.679037 -0500 AppleCameraAssistant StopHardwareStream 2019-08-31 22:59:59.809252 -0500 AppleCameraInterface default 0 22:59:59.809252 -0500 kernel AppleCamIn::power_off_hardware

I thought I could simply grep these message from the console.app but it seems to be easier said than done. I thought i could find the msgs in one of the console report files but When I look at the various reports on the console, i'm not finding a report that contains the messages above. How can I direct messages from console.app to a log file versus manually copying and pasting the info from the console?or point me to a direction? Am I missing something?
# 2  
Old 09-03-2019
Like your question before, you can (or should be able to) get this information more easily from the system profiler (than using log files):

Code:
system_profiler

See summary man page here:

https://www.unix.com/man-page/mojave/8/system_profiler/


Code:
root#  system_profiler -usage
Usage: system_profiler [-listDataTypes]
       system_profiler [-xml] [-timeout n] [-detailLevel n]
       system_profiler [-xml] [-timeout n] [dataType1 ... dataTypeN]

  -detailLevel n    specifies the level of detail for the report
                      mini = short report (contains no identifying or personal information)
                      basic = basic hardware and network information
                      full = all available information

  -listDataTypes    lists all the available datatypes

  -xml              generates xml output instead of plain text
                    if redirected to a file with the extension ".spx"
                    the file can be opened in System Profiler.app

  -timeout          specifies the maximum time to spend gathering information
                    the default is 180 seconds, 0 means no timeout

  Redirect stderr to /dev/null to suppress progress and error messages.

Examples:

  system_profiler
     Generates a text report with the standard detail level.

  system_profiler -detailLevel mini
     Generates a short report without identifying/personal information.

  system_profiler -listDataTypes
     Shows a list of the available data types.

  system_profiler SPSoftwareDataType SPNetworkDataType
     Generates a text report containing only software and network data.

  system_profiler -xml >MySystem.spx
     Creates a XML file which can be opened by System Profiler.app

This User Gave Thanks to Neo For This Post:
# 3  
Old 09-04-2019
Thanks Neo. I'm going to go back and review the system profiler and my results. I initially ran the system profiler full detail and did a search for this msg (AppleCamIn: power_on_hardware) and others. Looking at the profiler output but didn't see it using find. This msg and others I listed appear when I'm switching the audio and video inputs during a video conference session.
# 4  
Old 09-04-2019
Hey dallas88,

You should definitely see it enabled in the system_profiler output. Maybe try a few different system_profiler switches and system_profiler| grep -i "some keyword" searches to find it?

Please post back and let us know what you tried and what worked and what did not work.

Thanks!
# 5  
Old 09-05-2019
I ran a few searches in the system profiler and seem to be finding more info as try grep - i with different keywords. I will review more to spot other patterns but the first keyword search didn't land what i was looking for,

Code:
dddd$ system_profiler| grep -i "StartHardwareStream.*"
2019-09-04 23:29:06.218 system_profiler[87624:9749498] SystemInfo-AccessoryFW from dict - Magic Keyboard with Numeric Keypad = 0x0084
2019-09-04 23:29:06.218 system_profiler[87624:9749498] SystemInfo-AccessoryFW from dict - Magic Trackpad 2 = 0x0062
2019-09-04 23:29:06.219 system_profiler[87624:9749498] SystemInfo-AccessoryFW from dict - Magic Trackpad 2 = 0x0062
2019-09-04 23:29:08.111 system_profiler[87625:9749507] Attempting to add source to main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug.
2019-09-04 23:33:00.201 AllowPasswordPref[88030:9751089] error == Error Domain=com.apple.LocalAuthentication Code=-6 "Biometry is not available on this device." UserInfo={BiometryType=0, NSLocalizedDescription=Biometry is not available on this device.} isSupported ==  0
2019-09-04 23:33:00.201 AllowPasswordPref[88030:9751089] Hardware Check err == 0
2019-09-04 23:33:00.201 AllowPasswordPref[88030:9751089] Result -1
2019-09-04 23:33:01.894 AllowPasswordPref[88036:9751130] error == Error Domain=com.apple.LocalAuthentication Code=-6 "Biometry is not available on this device." UserInfo={BiometryType=0, NSLocalizedDescription=Biometry is not available on this device.} isSupported ==  0
2019-09-04 23:33:01.894 AllowPasswordPref[88036:9751130] Hardware Check err == 0
2019-09-04 23:33:01.894 AllowPasswordPref[88036:9751130] Result -1
2019-09-04 23:33:22.615 system_profiler[88128:9751465] SPUSBDevice: IOCreatePlugInInterfaceForService failed 0xe00002be

dddddd$ system_profiler| grep -i “camera”¯
   MassStorageCamera:
     Location: /System/Library/Image Capture/Devices/MassStorageCamera.app
   Type4Camera:
     Location: /System/Library/Image Capture/Devices/Type4Camera.app
   PTPCamera:
     Location: /System/Library/Image Capture/Devices/PTPCamera.app
2019-09-04 23:07:28.062 system_profiler[85082:9739521] SystemInfo-AccessoryFW from dict - Magic Keyboard with Numeric Keypad = 0x0084
2019-09-04 23:07:28.062 system_profiler[85082:9739521] SystemInfo-AccessoryFW from dict - Magic Trackpad 2 = 0x0062
2019-09-04 23:07:28.063 system_profiler[85082:9739521] SystemInfo-AccessoryFW from dict - Magic Trackpad 2 = 0x0062
2019-09-04 23:07:29.987 system_profiler[85083:9739526] Attempting to add source to main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug.
Camera:
     Model ID: UVC Camera VendorID_9665 ProductID_12
   FaceTime HD Camera (Built-in):
     Model ID: UVC Camera VendorID_1452 ProductID_34065
     Description: Simulates a camera lens flare effect.
   AppleCameraInterface:
     Bundle ID: com.apple.driver.AppleCameraInterface
     Get Info String: AppleCameraInterface, Copyright Ā© 2011 Apple Inc. All rights reserved.
     Location: /System/Library/Extensions/AppleCameraInterface.kext
   | |   |   | +-o FaceTime HD Camera (Built-in)@14400000  <class IOUSBHostDevice, id 0x100000316, registered, matched, active, busy 0 (13 ms), retain 25>
   | |   |   |   |   “USB Product Name”¯ = “FaceTime HD Camera (Built-in)”¯
   | |   |   |   +-o FaceTime HD Camera (Built-in)@0  <class IOUSBHostInterface, id 0x100000369, registered, matched, active, busy 0 (1 ms), retain 7>
     | |   +-o FaceTime HD Camera (Built-in)@14400000  <class AppleUSBDevice, id 0x100000340, registered, matched, active, busy 0 (7 ms), retain 20>
     | |   | |   “USB Product Name”¯ = “FaceTime HD Camera (Built-in)”¯
     | |   | +-o FaceTime HD Camera (Built-in)@0  <class AppleUSBInterface, id 0x10000036c, registered, matched, active, busy 0 (2 ms), retain 27>
     | |   | | |   “USB Interface Name”¯ = “FaceTime HD Camera (Built-in)”¯
       allowCamera:
2019-09-04 23:11:20.453 AllowPasswordPref[85500:9741184] error == Error Domain=com.apple.LocalAuthentication Code=-6 “Biometry is not available on this device.”¯ UserInfo={BiometryType=0, NSLocalizedDescription=Biometry is not available on this device.} isSupported ==  0
2019-09-04 23:11:20.454 AllowPasswordPref[85500:9741184] Hardware Check err == 0
2019-09-04 23:11:20.454 AllowPasswordPref[85500:9741184] Result -1
2019-09-04 23:11:22.198 AllowPasswordPref[85506:9741221] error == Error Domain=com.apple.LocalAuthentication Code=-6 “Biometry is not available on this device.”¯ UserInfo={BiometryType=0, NSLocalizedDescription=Biometry is not available on this device.} isSupported ==  0
2019-09-04 23:11:22.198 AllowPasswordPref[85506:9741221] Hardware Check err == 0
2019-09-04 23:11:22.198 AllowPasswordPref[85506:9741221] Result -1
   allowCamera = 1;
   iPhone 9,4 backtelephotocamera:
   iPad 8,3 backcamera:
   iPad 8,7 backcamera:
   iPhone 10,1 back camera:
   iPad 7,3 backcamera:
   iPhone 11,8 backcamera:
   iPhone 10,3 backcamera:
   iPad 8,4 backcamera:
   iPad 8,8 backcamera:
   iPhone 10,2 back telephoto camera:
   iPhone 9,1 backcamera:
   iPad 8,1 backcamera:
   iPhone 10,3 backtelephotocamera:
   iPhone SE backcamera:
   iPad 7,1 backcamera:
   iPhone 10,2 back camera:
   iPad Pro (9.7-inch) backcamera:
   iPhone 6s backcamera:
   iPad 8,2 backcamera:
   iPad 8,6 backcamera:
   iPhone 9,3 backcamera:
   iPhone 6s Plus backcamera:
   iPhone 9,4 backcamera:
2019-09-04 23:11:41.905 system_profiler[85561:9741516] SPUSBDevice: IOCreatePlugInInterfaceForService failed 0xe00002be
       FaceTime HD Camera (Built-in):

 
ddddd$ system_profiler| grep -i "AppleCamIn.*"
2019-09-05 00:01:09.783 system_profiler[91360:9764618] SystemInfo-AccessoryFW from dict - Magic Keyboard with Numeric Keypad = 0x0084
2019-09-05 00:01:09.785 system_profiler[91360:9764618] SystemInfo-AccessoryFW from dict - Magic Trackpad 2 = 0x0062
2019-09-05 00:01:09.786 system_profiler[91360:9764618] SystemInfo-AccessoryFW from dict - Magic Trackpad 2 = 0x0062
2019-09-05 00:01:11.662 system_profiler[91361:9764626] Attempting to add source to main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug.
2019-09-05 00:04:46.183 AllowPasswordPref[91862:9766511] error == Error Domain=com.apple.LocalAuthentication Code=-6 "Biometry is not available on this device." UserInfo={BiometryType=0, NSLocalizedDescription=Biometry is not available on this device.} isSupported ==  0
2019-09-05 00:04:46.183 AllowPasswordPref[91862:9766511] Hardware Check err == 0
2019-09-05 00:04:46.183 AllowPasswordPref[91862:9766511] Result -1
2019-09-05 00:04:47.970 AllowPasswordPref[91868:9766550] error == Error Domain=com.apple.LocalAuthentication Code=-6 "Biometry is not available on this device." UserInfo={BiometryType=0, NSLocalizedDescription=Biometry is not available on this device.} isSupported ==  0
2019-09-05 00:04:47.970 AllowPasswordPref[91868:9766550] Hardware Check err == 0
2019-09-05 00:04:47.970 AllowPasswordPref[91868:9766550] Result -1
2019-09-05 00:05:07.525 system_profiler[91923:9766828] SPUSBDevice: IOCreatePlugInInterfaceForService failed 0xe00002be

# 6  
Old 09-05-2019
Thanks.

It looks like the level of detail you are looking for is not available in system_profiler and you may have no choice but to use the logfiles (syslog) as you were doing (indirectly via console.app).

Console.app automatically shows system.log, and other log files, so you don't need to redirect entries from console.app but you need to find the (syslog) file which console.app used.

Make sense?

Example:

Code:
/var/log/system.log

You can monitor it easily using tail -f /var/log/system.log

Reference: see also the "logger" (man logger) and "syslog" (man syslog).

Please post back with the details of which log file you found had the information you need.

Thanks.
# 7  
Old 02-10-2020
This might not the best method but I used the Log show command to access the unified logs.
And then directed this to a file. So I use this to monitor the camera status.

Code:
#!/bin/bash
# Detects the status of the Apple Camera (Facetime).
Camstatus=$(log show --last 15m | grep 'AppleCamIn::')
echo "$Camstatus" >>~/library/logs/camera.log


I found out I can also can also run this command to collect the log info.
sudo log collect --output ~/Documents/logcoll.logarchive --start '2020-02-10'
(softron
HOW TO: Collect system logs on macOS Sierra and later – Softron Support Desk

I saw this post from @jollyRoger on the command to open the .logarchive formatted file.
Unified Logs | macOS High Sierra - Ask Different

Sorry I forgot to post back my gratitude for this great forum. Thanks Neo
Thanks, Ron -- still learning.
This User Gave Thanks to dallas88 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Cybersecurity

Best practice to allow 3rd party app to read messages file.

What is the best practice to allow a 3rd party health monitoring app to read the messages file. Since messages is a system file and is owned by root the app cannot read the file. I don't want to run the app as root so how should I allow the app to read the file. The read function is actually built... (2 Replies)
Discussion started by: slwiley
2 Replies

2. Shell Programming and Scripting

Manipulating sed Direct Input to Direct Output

Hi guys, been scratching round the forums and my mountain of resources. Maybe I havn't read deep enough My question is not how sed edits a stream and outputs it to a file, rather something like this below: I have a .txt with some text in it :rolleyes: abc:123:xyz 123:abc:987... (7 Replies)
Discussion started by: the0nion
7 Replies

3. UNIX for Dummies Questions & Answers

re-direct to log file

#!/bin/ksh -x cd /tmp/tj ftp -n servername.com << DONE user username password as put test.log quit close DONE echo "testing..." sh -x scriptname, and it shows all, but username, as, put, quit, close, DONE. how can i see those ? (1 Reply)
Discussion started by: tjmannonline
1 Replies

4. Shell Programming and Scripting

Need Mac .sh to run command line app in seperate terminal

Hello, currently we are executing a .sh from terminal. The current .sh looks like this: #!/usr/bin/env bash /Users/user/my.app/Contents/MacOS/my & -- Now, we also need to run a third line in the .sh - It's a command line application that I need to run when I execute the above .sh... (0 Replies)
Discussion started by: yoyoyo777
0 Replies

5. Shell Programming and Scripting

Set default app for file type on Mac

Hi there, We have 2 apps on our customers machines that can both open files with the same file extension. Is there any way via shell commands to set which application should be the default? Essentially, I'm hoping to replicate Get Info > Open With > Change All using a shell script, but I just... (0 Replies)
Discussion started by: davewg
0 Replies

6. Shell Programming and Scripting

Direct the output of a script to a log file

Hi, I have a script to compare 2 files. file1=$1 file2=$2 num_of_records_file1=`awk ' END { print NR } ' $file1` num_of_records_file2=`awk ' END { print NR } ' $file2` i=1 while do sed -n "$i"p $file1 > file1_temp sed -n "$i"p $file2 > file2_temp diff file1_temp... (5 Replies)
Discussion started by: autosys_nm
5 Replies

7. Shell Programming and Scripting

Re-direct the error msg to log file

Hi All, I have an expression as follows:- a=`expr ${i} + ${j}` >> $log_file 2>&1 Here, if any of the values i or j or both happens to be empty then the "expr" returns error as "expr: 0402-050 Syntax error." My problem is I am not able to re-direct this error to the log file. Its is getting... (4 Replies)
Discussion started by: rony_daniel
4 Replies
Login or Register to Ask a Question