bottle 文件服务器,如何登录到python&bottle web服务器的文件?

下面是我的服务器代码。我需要添加日志记录。这是一个非常基本的rest api服务器。我已经在Amazon EC2上部署了它。有时由于错误或其他原因,http服务器会关闭。如果我登录到EC2,我可以看到错误发生时。但如果我没有实时监控,我不知道发生了什么错误。因此,我想添加日志记录,这将在日志文件中记录错误,我可以稍后查看。请建议我怎么做。import json

import uuid # this is for generating unique id

import datetime

import bottle

from bottle import route, run, request, abort

from pymongo import Connection

connection = Connection('localhost', 27017)

db = connection.mydatabase

@route('/documents', method='PUT')

def put_document():

data = request.body.readline()

if not data:

abort(400, 'No data received')

entity = json.loads(data)

if not entity.has_key('_id'):

abort(400, 'No _id specified')

try:

db['documents'].save(entity)

except ValidationError as ve:

abort(400, str(ve))

@route('/documents/:id', method='GET')

def get_document(id):

entity = db['documents'].find_one({'_id':id})

if not entity:

abort(404, 'No document with id %s' % id)

return entity

@route('/startSession', method = 'GET')

def startSession():

#here we need to create a unique id and store it in the database.

date = str(datetime.datetime.utcnow());

id = str(uuid.uuid4())

reply = {'date' : date,

'user_id': id

}

response = {'date' : date,

'user_id': id

}

return_id = db['users'].save(reply)

#print 'the id returned is', return_id

#print 'the changed reply is',reply

#print 'the NON changed respponse is ',response

return json.dumps(response)

@route('/set_bus_location', method = 'PUT')

def set_bus_location():

data = request.body.readline()

print 'data is ',data

if not data:

abort(400, 'No data received')

entity = json.loads(data)

db['bus_locations'].save(entity)

run(host='0.0.0.0', port=8080)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值