title: Reading systemd journal from Python script
body: <p>I am trying to emulate this shell command in Python using the systemd libraries
  <a href="http://www.freedesktop.org/software/systemd/python-systemd/journal.html" rel="noreferrer">http://www.freedesktop.org/software/systemd/python-systemd/journal.html</a></p>
  
  <p>I am actually trying to emulate this command but within Python.</p>
  
  <pre><code>journalctl --since=-5m --no-pager
  </code></pre>
  
  <p>I have seen others do this in Python by calling the journal executable but that is a pretty bad way of doing it.</p>
  
  <p>I wrote this simple script based on the documentation linked above</p>
  
  <pre><code>import select
  from systemd import journal
  
  j = journal.Reader()
  j.log_level(journal.LOG_INFO)
  # j.add_match(_SYSTEMD_UNIT="systemd-udevd.service")
  
  j.seek_tail()
  j.get_next()
  
  while j.get_next():
      for entry in j:
          if entry['MESSAGE'] != "":
              print(str(entry['__REALTIME_TIMESTAMP'] )+ ' ' + entry['MESSAGE'])
  </code></pre>
  
  <p>There are a few issues here</p>
  
  <ol>
  <li>the log seems to start from about 5 days ago which means the seek_tail did not appear to work.</li>
  <li>I am getting a lot of junk in here is there a specific filter I should use to match the data I get from journalctl command given at the beginning of the question?</li>
  </ol>
  
  <p>Ideally longer term I want to just be following this journal based on a set of filters/matches to emulate the command 'journalctl -f' but I just need to resolve this issue first. I want to end up with something like this but it doesnt work either.</p>
  
  <pre><code>import select
  from systemd import journal
  
  j = journal.Reader()
  j.log_level(journal.LOG_INFO)
  
  # j.add_match(_SYSTEMD_UNIT="systemd-udevd.service")
  j.seek_tail()
  
  p = select.poll()
  p.register(j, j.get_events())
  while p.poll():
  
      while j.get_next():
          for entry in j:
              if entry['MESSAGE'] != "":
                  print(str(entry['__REALTIME_TIMESTAMP'] )+ ' ' + entry['MESSAGE'])
  </code></pre>