title: How to read /dev/log?
body: <p>I would like to directly access to <code>syslog</code> messages from Python by reading <code>/dev/log</code>.</p>
  
  <p>My (very limited) understanding is that the correct way is to read from there is to bind a datagram socket. </p>
  
  <pre><code>import socket
  
  sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
  sock.bind('/dev/log')
  sock.listen(1)
  while True:
      data, addr = sock.recvfrom(1024)
      print(data)
  </code></pre>
  
  <p>Apparently <code>/dev/log</code> is in use:</p>
  
  <pre><code>Traceback (most recent call last):
    File "readlog.py", line 4, in &lt;module&gt;
      sock.bind('/dev/log')
  OSError: [Errno 98] Address already in use
  </code></pre>
  
  <p><strong>How should I read <code>/dev/log</code> from Python?</strong></p>
  
  <hr>
  
  <p>EDIT: per @Barmar's comment - only one process can access <code>/dev/log</code> so that part is clear, the device must be clean before reading from it. <code>sudo lsof /dev/log</code> does not show anything.</p>
  
  <p><del><a href="https://stackoverflow.com/a/26324355/903011">A answer in a Java thread</a> around this subject mentioned that <code>syslog</code> should be shut down before. I also tried that, <code>lsof | grep "/dev/log"</code> was empty but I got the error nevertheless.<br>
  Isn't it possible to have several processes reading from <code>/dev/log</code>? </del></p>