how to make logging.logger to behave like print
<p>Let's say I got this <a href="https://docs.python.org/2/library/logging.html" rel="nofollow">logging.logger</a> instance:</p>

<pre><code>import logging
logger = logging.getLogger('root')
FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
logging.basicConfig(format=FORMAT)
logger.setLevel(logging.DEBUG)
</code></pre>

<p>Problem comes when I try to use it like the builtin print with a dynamic number of arguments:</p>

<pre><code>&gt;&gt;&gt; logger.__class__
&lt;class 'logging.Logger'&gt;
&gt;&gt;&gt; logger.debug("hello")
[&lt;stdin&gt;:1 -             &lt;module&gt;() ] hello
&gt;&gt;&gt; logger.debug("hello","world")
Traceback (most recent call last):
  File "c:\Python2711\Lib\logging\__init__.py", line 853, in emit
    msg = self.format(record)
  File "c:\Python2711\Lib\logging\__init__.py", line 726, in format
    return fmt.format(record)
  File "c:\Python2711\Lib\logging\__init__.py", line 465, in format
    record.message = record.getMessage()
  File "c:\Python2711\Lib\logging\__init__.py", line 329, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Logged from file &lt;stdin&gt;, line 1
</code></pre>

<p>How could i emulate the print behaviour still using logging.Logger?</p>

<p>Alternatively, define a function that accepts <code>*args</code> and then <code>join</code> them in your call to <code>logger</code>:</p>

<pre><code>def log(*args, logtype='debug', sep=' '):
    getattr(logger, logtype)(sep.join(str(a) for a in args))
</code></pre>

<p>I added a <code>logtype</code> for flexibility here but you could remove it if not required.</p>

python python-3.x logging