How to stop Time Machine backing up log files inside application containers? Time Machine does not backup log files in ~/Library/Logs

But it does backup logs files within application containers.  For example, log files in the folder ~/Library/Containers/com.apple.mail/Data/Library/Logs/Mail.

My Mail and OneDrive logs are currently adding about 2 GB per backup.

I could manually exclude each of ~/Library/Containers/*/Data/Library/Logs but that is a lot of exclusions and would be a list which needs addition whenever I install a new app.

The ~/Library/Containers/* folders were introduced to support sandboxing applications, but Time Machine seems to have not kept up with these changes.

Is there a better way of telling Time Machine to not backup the /Log folders within Containers?

I am using OS X Yosemite 10.10.1.
I had a similar need and using a combination of this answer and this answer I came up with the following solution.

Create a property list (e.g. ~/Library/LaunchAgents/excludeLogFiles.plist) which will be loaded with launchctl load ~/Library/LaunchAgents/excludeLogFiles.plist:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
  &lt;key&gt;Label&lt;/key&gt;
  &lt;string&gt;excludeLogFiles&lt;/string&gt;
  &lt;key&gt;ProgramArguments&lt;/key&gt;
  &lt;array&gt;
    &lt;string&gt;/bin/zsh&lt;/string&gt;
    &lt;string&gt;-c&lt;/string&gt;
    &lt;string&gt;tmutil addexclusion /Users/user/Library/Containers/**/Data/Library/Logs&lt;/string&gt;
  &lt;/array&gt;
  &lt;key&gt;WatchPaths&lt;/key&gt;
  &lt;array&gt;
    &lt;string&gt;/Users/user/Library/Containers&lt;/string&gt;
  &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Instead of using EnableGlobbing, which hasn't been supported since OS X 10.10 (ref), the path gets expanded by the program calling /bin/zsh &lt;args&gt;.

A couple of things I found while experimenting:


The ** glob works with zsh but not bash
Using ~ should work in the path for ProgramArguments but I don't know if the same trick can be used for WatchPath. Hard-coding the user path might be necessary.