简体   繁体   English

在本地项目中运行记录器效果很好,但在Heroku上失败

[英]Running a logger works fine in local project but fails on Heroku

Running a module called log.py creates a file my_file.log where it logs at what time the script ran. 运行名为log.py的模块将创建文件my_file.log ,并在该文件中记录脚本运行的时间。 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 . 在本地项目中运行log.py (过度)会写入一个日志文件,但由于某种原因,在heroku中的生产部署中运行它不会写入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. log.py还执行其他一些操作,我可以看出log.py确实在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 首先,我认为这可能是权限问题,但使用ls -l检查可以

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. 它与用作自定义Django命令的代码没有任何关系,因为在我的开发版本中,日志文件每次都应被覆盖。

This is the snippet in log.py responsible for logging to my_file.log : 这是log.py的片段,用于记录到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")

Heroku is read-only. Heroku是只读的。 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. 您正在尝试创建自己的日志文件my_file.log ,但无法执行此操作,因为您无法将任何内容写入其文件系统。

You can, however, print log messages to Heroku's standard logs. 但是,您可以将日志消息打印到Heroku的标准日志中。 Here are the docs for that. 这是该文档。 . You could then check your messages via heroku logs . 然后,您可以通过heroku logs检查消息。

In addition to Heroku's standard logging, they have many apps available for logging that you can install on your Heroku app. 除了Heroku的标准日志记录之外,它们还有许多可用于记录日志的应用程序,您可以将其安装在Heroku应用程序上。 Otherwise, you could consider using an email option or writing your log file to a third party location like s3 . 否则,您可以考虑使用电子邮件选项或将日志文件写入第三方位置(如s3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django 项目在本地工作但不在 heroku - Django Project works on local but not on heroku Django 应用程序在本地运行良好,但在登录管理员坐席时在 heroku 中失败 - Django app works fine locally, but fails in heroku when logging into admin sit Dockerized Flask 应用程序/在 Heroku 上崩溃,而本地运行的图像工作正常 - Dockerized Flask App / Crashing on Heroku while locally running image works fine 在本地运行heroku时出错 - Error running heroku local 使用数据库连接将代码部署到Azure Web时,Flask应用程序无法呈现,但是在本地服务器上运行良好 - Flask app fails to render when deploying code to Azure Web with a database connection, but works fine from local server Learn Python中的项目“ Gothonweb”,Hard Way ex50在Ubuntu上运行良好,在win7上失败 - Project “Gothonweb” in Learn Python the Hard Way ex50 works fine on Ubuntu, fails on win7 找不到Python模块 <project> 仅在VPS上。 在本地计算机上工作正常 - Python module not found <project> only on VPS. works fine on local machine Flask项目在本地环境中工作,在heroku上引发有关丢失文件的怪异错误(无论如何这些文件都是动态添加的!) - Flask project works in local environment, throws weird error on heroku about missing files (that are dynamically added anyway!) Heroku Local 工作正常,它连接到 Heroku 托管的 Postgresql DB。 一旦尝试部署,得到错误代码=H14 status=503 - Heroku Local works fine and it is connected to Postgresql DB hosted by Heroku. Once attempt to deploy, got error code=H14 status=503 pip3失败,但是pip与virtualenv可以正常工作 - pip3 fails but pip works fine with virtualenv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM