2

While running Django project, I am getting the following error:

Unhandled exception in thread started by <function wrapper at 0x7fe72b054b50> 

Traceback (most recent call last):   
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
        fn(*args, **kwargs)   
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 107, in inner_run
        autoreload.raise_last_exception()   
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 252, in raise_last_exception
        six.reraise(*_exception)   
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
        fn(*args, **kwargs)   

File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 17, in setup
        configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)   File "/usr/local/lib/python2.7/dist-packages/django/utils/log.py", line 86, in configure_logging
        logging_config_func(logging_settings)   
File "/usr/lib/python2.7/logging/config.py", line 794, in dictConfig
        dictConfigClass(config).configure()   
File "/usr/lib/python2.7/logging/config.py", line 576, in configure
        '%r: %s' % (name, e)) 
    
ValueError: Unable to configure handler 'ap_migration_log': [Errno 2] No such file or directory: '/home/dg/Desktop/project_dir/django_project/
    module_a/management/commands/log/ap_migration_log'

One solution I found on stackoverflow is to create these files and then this error will not occur. But, why can't Django create log files on its own when required? Is there any config setting or command to make sure that logging file isn't created manually?

1

1 Answer 1

1

Make sure that if you're writing the logs to /my/log/dir/log.txt, that path exists along with the empty log.txt file. Also make sure that your directory has the right permissions to perform CRUD operations. Same goes to the file.

It's best practice to store log files in /var/log/ directory.

Have a look at https://docs.djangoproject.com/en/3.0/topics/logging/#configuring-logging for examples on how Django logging works.

Sign up to request clarification or add additional context in comments.

1 Comment

In addition, you could have setting.py create the missing director structure prior to enabling the logging system. There's a bit of danger with that. This means if you do that and the direct recreation fails, that's not gonna be logged normally. However, it's a relatively simple action, and if it fails, the application terminates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.