我阅读了Joyent的postmortem调试文章,他们建议我们使用bunyan.
他们讨论了日志信息的质量如何非常重要,并有助于在出现错误时解决错误.然后有外部博客网站显示如何在他们的Nodejs应用程序中安装和运行bunyan,这很不错.
但我是如何有效地使用日志记录(一般都是针对bunyan和日志记录实践)的新手.我有三个相互关联的问题.
(1)我是否应该使用bunyan来记录我的申请中发生的每一个动作?
即
router.post('/submit', function(req, res) {
log.info({ req:req }, req.user.name + ' has called /submit');
saveData(req)
.then(function(data) {
log.info({data: data}, req.user.name + ' has saved to DB successfully in /submit');
res.json({'success': 'Saved!'});
})
.error(function(err) {
log.error({ err: err }, req.user.name + ' has caused an error in /submit ');
res.status(500).json("error": err});
});
});
Run Code Online (Sandbox Code Playgroud)
...... 在我的申请中到处都是这样的?
(2)如果是这样,那么我不会以脱节的方式得到日志输出吗?例如,如果我们有3个并发用户呼叫/submit,则消息可以是:
Alice has called /submit
Bob has called /submit
Alice has caused an error in …Run Code Online (Sandbox Code Playgroud) 我大致遵循Flask的这个部署指南.当我通过uwsgi启动我的应用程序时,收到错误:
***操作模式:preforking***
无法加载应用0(mountpoint ='')(未找到可调用或导入错误)
***没有加载应用.进入完全动态模式***
这是与其他SO问题相同的问题,因此它是一个python路径问题,但我仍然无法让我的应用程序运行.这是我的设置:
/home/btw/prod/
.... app.py
.... inits.py
.... templates/
.... wsgi.py
.... prod.ini
.... env/ <--- virtualenv dir
Run Code Online (Sandbox Code Playgroud)
inits.py
# This initializes everything
from flask import Flask
#... other imports
app = Flask(__name__)
app.debug = False
# Flask-Migrate
migrate = Migrate(app,db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
Run Code Online (Sandbox Code Playgroud)
app.py
# This holds the main application code and routes
from inits import *
@app.route('/doit')
def doit():
return render_template('doit.html')
if __name__ == '__main__':
manager.run()
Run Code Online (Sandbox Code Playgroud)
prod.ini
[uwsgi] …Run Code Online (Sandbox Code Playgroud) 我有一个带图像的div:
<div ng-if="showIt">
<img src="{{filepath}}/{{filename}}">
<!-- ... and a bunch other other elements -->
</div>
Run Code Online (Sandbox Code Playgroud)
事情是{{filepath}},{{filename}}如果showIt是假的话将是null .
但是,我总是在控制台中看到404错误,因为我认为Angularjs正在呈现整个DOM,然后删除ng-if评估为false 的位.这意味着即使showIt是假的,浏览器也总是会请求不存在的图像.
有没有办法阻止DOM创建整个div块,以便浏览器永远不会请求不存在的图像?
Flask教程有一个在发生错误时通过电子邮件发送自己的示例.我想添加一些信息request,但一直收到错误:
RuntimeError: working outside of request context
Run Code Online (Sandbox Code Playgroud)
这是我有的:
if __name__ == '__main__':
if not app.debug:
# create mail handler
import logging
from logging.handlers import SMTPHandler
mail_handler = SMTPHandler('127.0.0.1',
'server-error@example.com',
['admin@example.com'], 'YourApplication Failed')
# Log format
from logging import Formatter
mail_handler.setFormatter(Formatter('''
Message type: %(levelname)s
Location: %(pathname)s:%(lineno)d
Module: %(module)s
Function: %(funcName)s
Time: %(asctime)s
Message:
%(message)s
''' % request.headers )) # Added request here
# Attach log handler to app
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
Run Code Online (Sandbox Code Playgroud)
如何获取日志记录的请求上下文?
我正在使用 Stripe API 进行测试,但无法让这个基本的“市场”场景发挥作用。该场景是买家从卖家处购买,应用程序需要付费。
我的设置:
# Seller has already connected their account to the application
# through "Stripe Connect Standalone". Below will attempt to charge a customer.
import stripe
# application's sk from stripe
stripe.api_key = "sk...."
# Build customer
customer = stripe.Customer.create(
email = customer.email,
card = token_from_stripe_checkout
)
# Now do a charge
charge = stripe.Charge.create(
amount = 2000,
currency = "usd",
customer = customer.id,
application_fee = 500,
stripe_account = seller.stripe_user_id # which is something like: acct_xxxxxxxxx
) …Run Code Online (Sandbox Code Playgroud)