title: Why do I get a spurious ']' character in syslog messages with Python's SysLogHandler on OS X?
body: <p>With Python 3.5 on OS X 10.10.4, I get spurious <code>]</code> characters in the output syslog messages. This can be seen with the following sample program:</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import logging
  import logging.handlers
  
  logger = logging.getLogger('test')
  
  syslog_handler = logging.handlers.SysLogHandler(address='/var/run/syslog')
  syslog_formatter = logging.Formatter('[{process}] {message}', style='{')
  syslog_handler.setFormatter(syslog_formatter)
  
  logger.addHandler(syslog_handler)
  logger.error("Test : ABC")
  </code></pre>
  
  <p>If I run this, I see syslog output like this:</p>
  
  <pre><code>Dec 16 12:38:33 mymachinename [76399] Test]: ABC
  </code></pre>
  
  <p>(Note the spurious <code>]</code> character after <code>Test</code>).</p>
  
  <p>If I change the formatter string slightly to remove the initial <code>[</code> character, the additional <code>]</code> disappears. However, I wish this literal character to appear in the formatted string (and I have the same problem even if it's not at the beginning of the formatting string).</p>
  
  <p>Why does this spurious <code>]</code> appear, and how can I avoid it?</p>
  
  <p>OS X's <code>asl.conf</code>, which is where logging is configured, looks like this. I have not modified it from the defaults:</p>
  
  <pre><code>##
  # configuration file for syslogd and aslmanager
  ##
  
  # authpriv messages are root/admin readable
  ? [= Facility authpriv] access 0 80
  
  # remoteauth critical, alert, and emergency messages are root/admin readable
  ? [= Facility remoteauth] [&lt;= Level critical] access 0 80
  
  # broadcast emergency messages
  ? [= Level emergency] broadcast
  
  # save kernel [PID 0] and launchd [PID 1] messages
  ? [&lt;= PID 1] store
  
  # ignore "internal" facility
  ? [= Facility internal] ignore
  
  # save everything from emergency to notice
  ? [&lt;= Level notice] store
  
  # Rules for /var/log/system.log
  &gt; system.log mode=0640 format=bsd rotate=seq compress file_max=5M all_max=50M
  ? [= Sender kernel] file system.log
  ? [&lt;= Level notice] file system.log
  ? [= Facility auth] [&lt;= Level info] file system.log
  ? [= Facility authpriv] [&lt;= Level info] file system.log
  ? [= Facility user] [&lt;= Level debug] file system.log
  
  # Facility com.apple.alf.logging gets saved in appfirewall.log
  ? [= Facility com.apple.alf.logging] file appfirewall.log file_max=5M all_max=
  </code></pre>
  
  <p>I do <em>not</em> see the same problem on Ubuntu 10.04, so it appears to be OS X-specific.</p>