Kill all logging in macOS Sierra – and (maybe) save battery life

16 March 2017, 10:00

Feature head image

A few days ago I blogged about how to deactivate runaway logging for certain apps and processes in macOS, something which seems to be a very recent problem introduced with the macOS Sierra update. It has been known to consume increasing amounts of CPU time, making the fans spin-up and gobbling-up battery life on portable Macs.

Below are the steps required to turn off, as much as is possible, all app and process logging in macOS Sierra. Again, I have to point out that this only turns off logging and as such is utterly harmless. You’re not quitting any apps or processes, or hindering them in any way.

I have to admit that this is an effective but ultimately hacky solution for turning off logging but I’m unable to find any other way of achieving it (and certainly not an “official” method – I don’t believe Apple ever intended anybody to turn off logging, even though 99.99% of users do not need it or are unaware of it).

The benefits of turning off most app/process logging might include significantly improved battery life. This is what I believe I’ve experienced, in any event. Let me know in the comments below what your findings are.

What we’re going to do
The steps below aren’t for beginner users, and consist of two main components. The first is a script that simply runs through virtually all possible process IDs (PIDs), and upon finding a PID that matches an actual app or process, summarily kills its logging. Just before quitting the script deletes any existing log files to free-up disk space. The second part of the hack involves a launchd plist that causes this script to run each time the Mac boots, and every 30 minutes subsequently. It runs in the background, invisibly, and is set to have the least possible impact on your system. In other words, you shouldn’t be aware it’s there aside from the fact that using the Console app should show significantly fewer entries.

Nonetheless, you do need to remember the hack is in place. Apple might fix the whole runaway logging problem in an update of macOS, for example, making it redundant. Or you might actually need the diagnostic data that logging provides in order to solve a problem with your computer. I also provide instructions below detailing how to deactivate this hack.

Remember: These steps only work on macOS Sierra (and possibly later releases of macOS). They will NOT work on earlier version of OS X, which used a completely different logging system.

The steps required
Here are the steps required:

  1. Open the Terminal app, which you’ll find in the Utilities folder of the Applications list of Finder.

  2. Copy and paste the following into the Terminal window, entering your login password when prompted. You might see a scary-looking warning message but this is fine and you can continue. Note that this is a single line of code even though it might appear as several lines in your browser – just triple-click any line to select the whole thing, then Cmd+C to copy it, before hitting Cmd+V to paste it into the Terminal window:
    sudo curl -L https://goo.gl/sQ1cFj > /usr/local/bin/logkill.sh;sudo chmod +x /usr/local/bin/logkill.sh

  3. In the Terminal window type whoami, and then select and copy the result.
    Main feature illustration

  4. In the Terminal window, type the following, which will open the script for editing in the Terminal window:
    sudo nano /usr/local/bin/logkill.sh

  5. Using the cursor keys, move the text cursor to the very bottom line. See the word USERNAME? Delete this, and then paste in what you copied in Step 3. For example, on my system where my username is keir, this is how that last line in the file looked:
    rm -rf /Users/keir/Library/Logs/*

  6. In the Terminal window tap Ctrl+O, hit Enter, and then Ctrl+X. This will save the file and close the text editor. Note that you’re using the Ctrl key there, not the Cmd key!

  7. Copy and paste the following into the Terminal window – again it’s a single line of code, so triple-click etc.
    sudo curl -L https://goo.gl/85bxlN > com.mackungfu.kill-logging.plist;sudo cp com.mackungfu.kill-logging.plist /Library/LaunchDaemons/;rm com.mackungfu.kill-logging.plist

  8. Finally, type the following to activate everything (again, this is a single line of code):
    sudo launchctl load -w /Library/LaunchDaemons/com.mackungfu.kill-logging.plist

You can now close the Terminal window. The log killing background service is now running, and will restart upon every boot of the computer.

Deactivating
Should you want to turn off the logging killing service, paste the following into Terminal (which again is a single line):

sudo launchctl unload -w /Library/LaunchDaemons/com.mackungfu.kill-logging.plist

If you want to remove the scripts added previously, paste in the following (again a single line of code):

sudo rm /usr/local/bin/logkill.sh; sudo rm /Library/LaunchDaemons/com.mackungfu.kill-logging.plist

Problems with this method
As you might realise if you implement the steps above, this is not a perfect solution. Any apps or processes that launch between instances of the script running in the background will not be blocked from spewing log output. Some launch, spew log output for a few minutes, and then quit. However, the script will eventually run again on its 30 minute cycle so any long term offenders should get caught and dealt with. Additionally, because Safari treats each new browser tab as a separate process, a big issue is that Console log output will fill quickly once more with masses of com.apple.WebKit.* log output, and the method above doesn’t address this. However, in stopping most other log output, the benefits are still very significant.

Main feature illustration

Credits
Many thanks to Jon H for creating the bash script used here.


Leave a comment...

 
---