You can use custom Filter, as it says unutbu, or you can use LoggerAdapter:
import logging
logger = logging.LoggerAdapter(logging.getLogger(__name__), {'MYVAR': 'Jabberwocky'})
FORMAT = '%(MYVAR)s %(asctime)s - %(levelname)s - %(message)s'
logging.basicConfig(format=FORMAT, datefmt='%d/%m/%Y %H:%M:%S')
logger.warning("'Twas brillig, and the slithy toves")
which gives
Jabberwocky 04/25/2013 07:39:52 - WARNING - 'Twas brillig, and slithy toves
:
import logging
logger = logging.getLogger(__name__)
FORMAT = '%(MYVAR)s %(asctime)s - %(levelname)s - %(message)s'
logging.basicConfig(format=FORMAT, datefmt='%d/%m/%Y %H:%M:%S')
logger.warning("'Twas brillig, and the slithy toves", extra={'MYVAR': 'Jabberwocky'})
.
MYVAR , LoggerAdapter , Filter .