How can I log all notifications?
As was linked by Arthur Hammer, https://apple.stackexchange.com/a/142811/37689 states that notifications are stored in an SQLite database. The following python script should get you started:

#!/usr/bin/env python
import os
import re
import sqlite3

# Location of notification centers database under Yosemite
tmp = os.environ['TMPDIR']
conn = sqlite3.connect(tmp + '/../0/com.apple.notificationcenter/db/db')

for notification in conn.execute('SELECT * from notifications'):
    encoded_data = str(notification[-1]) # last item
    clean = re.sub('[^\w\s-]', '', encoded_data) # remove some funny stuff (fixme: removes too much?)
    sp = clean.split('\t')
    # Find NSActualdeliverydate, message content seems to always come after this
    for ix in range(len(sp)):
        if 'NSActualdeliverydate' in sp[ix]:
            break
    # Skip blanks
    for ix in range(ix+1, len(sp)):
        if sp[ix] != '': break

    print 'notification', sp[ix].replace('_', '\n').strip()

conn.close()


You can then either pipe this to a file and then grep the file, or just grep the output of the script directly.