With this setting, I have only one file logged:

logging.basicConfig(format=u'%(levelname)-8s [%(asctime)s] %(message)s', level=logging.DEBUG, filename=os.path.join('logs', __name__)) 

How to configure the logger so that the logs are written for several files and for each file there is a file with logs?

    1 answer 1

    Use the recipe book for logging

    In a simplified version: create a separate log for each of your tasks / module / logical structure

     logger = logging.getLogger(__name__) 

    Example:

     import logging logger = {} logger['warning'] = logging.getLogger('MYWARNING') logger['error'] = logging.getLogger('MYERROR') logger['warning'].warning("Warning log!") logger['error'].error("Error log!") 
    • This does not work. If you do this, then the logs will be recorded in the first name specified in getLogger e. - faoxis
    • So use the list and create several logging instances. What is the problem? - RemiZOffAlex
    • Show with an example what you are talking about. - faoxis
    • Showed in response. - RemiZOffAlex
    • one
      mywarning, myerror is a bad misleading example. Better names like django.request , myproject.custom use. For each logger to write to its own separate file, they need to set up a FileHandler (separate for each logger). Configuration can be set using a dictionary or from an ini file to read. - jfs