Reputation: 11028
Running a module called log.py
creates a file my_file.log
where it logs at what time the script ran. Running log.py
(over)writes to a log file perfectly fine in my local project but for some reason running it on my production deploy in heroku doesn't write to my_file.log
. The log.py
also does some other things and I can tell by that that log.py
did indeed execute in Heroku. It's only the logs that aren't written.
First I thought it could be a permissions problem but checking with ls -l
gives
drwx------ 3 my_app
-rw------- 1 my_file.log
The following is my project structure:
.
├── my_project
│ ├── my_app
│ │ ├── __init__.py
│ │ ├── models.py
│ │ ├── tests.py
│ │ ├── views.py
│ │ ├── my_file.log
│ │ └── management
│ │ ├── __init__.py
│ │ └── commands
│ │ ├── __init__.py
│ │ └── log.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
└── requirements.txt
It shouldn't have anything to do with the code being used as a custom Django command because in my development version the log file is overwritten each time as it should.
This is the snippet in log.py
responsible for logging to my_file.log
:
log_lc = os.path.join(os.path.dirname(os.path.abspath(__file__)),
os.path.pardir, os.path.pardir, "my_file.log")
logging.basicConfig(filename=log_lc,level=logging.INFO,
format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p',
filemode="w")
logging.info("You just ran my_file.log")
Upvotes: 0
Views: 83
Reputation: 6320
Heroku is read-only. You are trying to create your own log file, my_file.log
, and you will not be able to do that since you cannot write anything to their file system.
You can, however, print log messages to Heroku's standard logs. Here are the docs for that.. You could then check your messages via heroku logs
.
In addition to Heroku's standard logging, they have many apps available for logging that you can install on your Heroku app. Otherwise, you could consider using an email option or writing your log file to a third party location like s3
.
Upvotes: 4