Skip to content

Commit

Permalink
添加sentry日志,需要 python3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mailgyc committed Jan 9, 2019
1 parent 3d1531e commit a3d90eb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
8 changes: 3 additions & 5 deletions core/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from core.player import Player
from handlers.protocol import Protocol as Pt

logger = logging.getLogger('ddz')


class AiPlayer(Player):

Expand All @@ -20,10 +18,10 @@ def __init__(self, uid: int, username: str, player: Player):
def to_server(self, message):
packet = json.dumps(message)
IOLoop.current().add_callback(self.socket.on_message, packet)
logger.info('AI[%d] REQ: %s', self.uid, message)
logging.info('AI[%d] REQ: %s', self.uid, message)

def from_server(self, packet):
logger.info('AI[%d] ON: %s', self.uid, packet)
logging.info('AI[%d] ON: %s', self.uid, packet)
code = packet[0]
if code == Pt.RSP_LOGIN:
pass
Expand Down Expand Up @@ -53,7 +51,7 @@ def from_server(self, packet):
winner = packet[1]
coin = packet[2]
else:
logger.info('AI ERROR PACKET: %s', packet)
logging.info('AI ERROR PACKET: %s', packet)

def auto_call_score(self, score=0):
# millis = random.randint(1000, 2000)
Expand Down
4 changes: 1 addition & 3 deletions core/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from core import Singleton
from core.table import Table

logger = logging.getLogger('ddz')


class Room(object):

Expand All @@ -14,7 +12,7 @@ def __init__(self, uid, allow_robot=True):
self.__playing_tables = {}
self.allow_robot = allow_robot
self.entrance_fee = 100
logger.info('ROOM[%d] CREATED', uid)
logging.info('ROOM[%d] CREATED', uid)

def rsp_tables(self):
rsp = []
Expand Down
4 changes: 1 addition & 3 deletions core/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import logging
import json

logger = logging.getLogger('ddz')

'''
# A 2 3 4 5 6 7 8 9 0 J Q K W w
# 记分
Expand Down Expand Up @@ -148,6 +146,6 @@ def _card_type(cards):
value = _index_of(rules[t], cards)
if value >= 0:
return t, value
logger.info('Unknown Card Type: %s', cards)
logging.info('Unknown Card Type: %s', cards)
# raise Exception('Unknown Card Type: %s' % cards)
return '', 0
18 changes: 8 additions & 10 deletions core/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

from tornado.ioloop import IOLoop

from core.robot import AiPlayer
from core.robot import AiPlayer, Player
from handlers.protocol import Protocol as Pt

logger = logging.getLogger('ddz')


class Table(object):

Expand All @@ -20,7 +18,7 @@ class Table(object):
def __init__(self, uid, room):
self.uid = uid
self.room = room
self.players = [None, None, None]
self.players: List[Player] = [None, None, None]
self.state = 0 # 0 waiting 1 playing 2 end 3 closed
self.pokers: List[int] = []
self.multiple = 1
Expand Down Expand Up @@ -50,7 +48,7 @@ def reset(self):
if self.is_full():
self.deal_poker()
self.room.on_table_changed(self)
logger.info('TABLE[%s] GAME BEGIN[%s]', self.uid, self.players[0].uid)
logging.info('TABLE[%s] GAME BEGIN[%s]', self.uid, self.players[0].uid)

def ai_join(self, nth=1):
size = self.size()
Expand Down Expand Up @@ -104,7 +102,7 @@ def call_score_end(self):
response = [Pt.RSP_SHOW_POKER, self.turn_player.uid, self.pokers]
for p in self.players:
p.send(response)
logger.info('Player[%d] IS LANDLORD[%s]', self.turn_player.uid, str(self.pokers))
logging.info('Player[%d] IS LANDLORD[%s]', self.turn_player.uid, str(self.pokers))

def go_next_turn(self):
self.whose_turn += 1
Expand All @@ -122,7 +120,7 @@ def handle_chat(self, player, msg):

def on_join(self, player):
if self.is_full():
logger.error('Player[%d] JOIN Table[%d] FULL', player.uid, self.uid)
logging.error('Player[%d] JOIN Table[%d] FULL', player.uid, self.uid)
for i, p in enumerate(self.players):
if not p:
player.seat = i
Expand Down Expand Up @@ -150,19 +148,19 @@ def on_game_over(self, winner):
p.send(response)
# TODO deduct coin from database
# TODO store poker round to database
logger.info('Table[%d] GameOver[%d]', self.uid, self.uid)
logging.info('Table[%d] GameOver[%d]', self.uid, self.uid)

def remove(self, player):
for i, p in enumerate(self.players):
if p and p.uid == player.uid:
self.players[i] = None
self.history[i] = None
else:
logger.error('Player[%d] NOT IN Table[%d]', player.uid, self.uid)
logging.error('Player[%d] NOT IN Table[%d]', player.uid, self.uid)

if all(p is None for p in self.players):
self.state = 3
logger.error('Table[%d] close', self.uid)
logging.error('Table[%d] close', self.uid)
return True
return False

Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
aiomysql==0.0.20
bcrypt==3.1.4
coverage==4.5.2
Pillow==5.3.0
Tornado==5.1.1
pillow==5.3.0
pymysql==0.9.2
sentry-sdk==0.6.6
tornado==5.1.1

11 changes: 10 additions & 1 deletion settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tornado.options import define, options

define("port", default=8080, help="run on the given port", type=int)
define("debug", default=False, help="debug mode")
define("debug", default=True, help="debug mode")
define("host", default="localhost", help="Database host")
define("database", default="ddz", help="Database name")
define("user", default="root", help="username")
Expand All @@ -25,6 +25,15 @@
'debug': options.debug,
}

if not options.debug:
import sentry_sdk
from sentry_sdk.integrations.tornado import TornadoIntegration
sentry_sdk.init(
'https://[email protected]/1366504',
integrations=[TornadoIntegration()]
)


DATABASE = {
'host': options.host,
'database': options.database,
Expand Down

0 comments on commit a3d90eb

Please sign in to comment.