Can you shorten logging headers when using python logging `%(funcName)s`?
<p>Sometimes I configure the python logging formatter using the <code>%(funcName)s</code>. But I don't like this when the function names are really long.</p>

<p><strong>Can you shorten logging headers when using python logging <code>%(funcName)s</code>? If yes, how?</strong></p>

<p>Can you say... limit the total number of characters to like 10 characters?</p>

<p>The <code>%(...)s</code> items in the logging format string are % replacements, and you can limit the length of a string replacement by doing something like <code>%(funcName).10s</code></p>

<p>e.g.</p>

<pre><code>import logging

logging.basicConfig(
    format='%(funcName).10s %(message)s',
    level=logging.INFO,
)

logger = logging.getLogger()

def short():
    logger.info("I'm only little!")

def really_really_really_really_long():
    logger.info("I'm really long")

short()
really_really_really_really_long()
</code></pre>

<p>gives</p>

<pre><code>andy@batman[17:54:01]:~$ p tmp_x.py 
short I'm only little!
really_rea I'm really long
</code></pre>

python logging instrumentation