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 > /usr/local/bin/;sudo chmod +x /usr/local/bin/

  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/

  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 > 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.

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/; 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* 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

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

Leave a comment...

There is a better way :

sudo lauchctl unload /System/Library/LaunchDaemons/

Why kill the processes one by one when you can kill the daemon responsible of the logging system ?

— sp · Nov 16, 06:18 AM · #

There is a better way :

sudo lauchctl unload /System/Library/LaunchDaemons/

Why kill the processes one by one when you can kill the daemon responsible of the logging system ?

Correction :

After trying that, I had a bootloop. Restarted in recovery mode. I had to edit manually with a terminal editor. No big deal. :)

— sp · Nov 16, 07:38 AM · #

I tested your script which to get through all possible pid with “NUM=ps -o pid -p $i | grep $I” and get only the actual pids.

It is very cpu intensive and take 7 minutes just to collect the pid of ~650 running process without any other command added, prompting the fan to activate, which only occurs for ressource intensive processes, that on a MacBook Pro 2015 13’.

You basically run 70,000 times the command “ps -o pid -p $i | grep $I” (which is in fact 2 commands) which only return 1% of actual process’s pid.

Which goes again the goal of saving battery and cpu time.

I found a more efficient ps command which take less than 1 seconde and collect as much as actual pid:


for i in $(ps -ax -opid=); do echo $I #Uncomment following line… #log config —process=$i —mode ‘level:off’;

In short the “$(ps -ax -opid=)” command return a bash array.

In the current script, we iterate through the array returned by this “ps” command (run only once), including all the pid of the running processes, and apply the “log config —process=$i —mode ‘level:off’;” command on each of them ($i)

Thus, instead of running 70000 “ps” command to check the existence hypothetical processes pid ($i) ; we we run the “ps” command only once and iterate through the returned array and apply “log config —process=$i —mode ‘level:off’;” on each element of that array.

The current “ps” command is 70,000 more efficient.

— Stephane Piriou · Nov 17, 06:12 AM · #