How to set output for logging.handlers.SysLogHandler in YAML file in python
<p>I have following config file:</p>

<pre><code>[loggers]
keys=MYLogger

[handlers]
keys=fileHandler,streamHandler,sysHandler

[formatters]
keys=simpleFormatter

[logger_MYLogger]
level=INFO
handlers=fileHandler
qualname=MYLogger
propagate=0

[handler_fileHandler]
class=FileHandler
formatter=simpleFormatter
args=('mylog.log',)

[handler_streamHandler]
class=StreamHandler
formatter=simpleFormatter
args=(sys.stdout,)

[handler_sysHandler]
class=logging.handlers.SysLogHandler
formatter=simpleFormatter
args=('/dev/log',)


[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s : %(message)s
datefmt=%Y-%m-%d %H:%M:%S
</code></pre>

<p>I need to convert it to the YAML file. I've done it successfully, except part for sysHandler:</p>

<pre><code>  version: 1
  formatters:
    simpleFormatter:
      format: '%(asctime)s - %(name)s - %(levelname)s : %(message)s'
      datefmt: '%Y-%m-%d %H:%M:%S'
  handlers:
    stream:
      class: logging.StreamHandler
      formatter: simpleFormatter
      stream: ext://sys.stdout
    file:
      class: logging.FileHandler
      formatter: simpleFormatter
      filename: mylog.log
    # sys:
    #   class: logging.handlers.SysLogHandler
    #   formatter: simpleFormatter
    #   stream: /dev/log
  loggers: 
    MYLogger:
      level: INFO
      handlers: [stream, file]
</code></pre>

<p>How to provide arguments for sysHandler in yaml format? Why it was ok to simply put args in original config file and here I have to specify stream / filename?</p>

<p>The logging <a href="https://docs.python.org/3/library/logging.config.html#dictionary-schema-details" rel="nofollow">dictionary schema details</a> have the following to say about handlers:</p>

<pre><code>handlers - the corresponding value will be a dict in which each key is a handler 
id and each value is a dict describing how to configure the corresponding Handler
instance.

The configuring dict is searched for the following keys:

    class (mandatory). This is the fully qualified name of the handler class.
    level (optional). The level of the handler.
    formatter (optional). The id of the formatter for this handler.
    filters (optional). A list of ids of the filters for this handler.

All other keys are passed through as keyword arguments to the handlerâs
constructor.
</code></pre>

<p>The SysLogHandler has the following <a href="https://docs.python.org/3/library/logging.handlers.html#logging.handlers.SysLogHandlerhttp://" rel="nofollow">signature</a>:</p>

<pre><code>SysLogHandler(address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER, socktype=socket.SOCK_DGRAM)
</code></pre>

<p>The key <code>stream</code>, which is not a mandatory or optional key for a handler, is passed as keyword argument to <code>SysLogHandler()</code> and that is not a keyword you can use to instantiate an instance of that class.</p>

<p>The non-mandatory/optional keys for the <a href="https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler" rel="nofollow">StreamHandler</a> (i.e. <code>stream</code>) and <a href="https://docs.python.org/3/library/logging.handlers.html#logging.FileHandler" rel="nofollow">FileHandler</a> (i.e. <code>filename</code>) match the respective signatures).</p>

<p>I assume you really have to supply to suppy the address with the tuple argument as sequence, to get this accepted:</p>

<pre><code>sys:
    class: logging.handlers.SysLogHandler
    formatter: simpleFormatter
    address: [localhost, /dev/log]
</code></pre>

<p>(Please note that the <code>args</code> entry for <code>[handler_sysHandler]</code> in your INI style config file should start with a tuple. From the <a href="https://docs.python.org/3/library/logging.config.html#configuration-file-format" rel="nofollow">logging documentation</a>:</p>

<pre><code>args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
</code></pre>

python logging yaml syslog