From 8256a4785182041503b9dc94cb41c1c32af5257c Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Wed, 6 Feb 2019 18:28:24 +0100 Subject: [PATCH] logging & fixes --- server/mapobject/logger.go | 11 +++++++++++ server/mapobject/setup.go | 12 ++++++++++++ server/mapobjectdb/accessor.go | 13 ++++++++++--- server/mapobjectdb/logger.go | 11 +++++++++++ server/mapobjectdb/sqlite/mapobjects.go | 16 +++++++++------- 5 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 server/mapobject/logger.go create mode 100644 server/mapobjectdb/logger.go diff --git a/server/mapobject/logger.go b/server/mapobject/logger.go new file mode 100644 index 0000000..57d67fb --- /dev/null +++ b/server/mapobject/logger.go @@ -0,0 +1,11 @@ +package mapobject + +import ( + "github.com/sirupsen/logrus" +) + +var log *logrus.Entry + +func init() { + log = logrus.WithFields(logrus.Fields{"prefix": "mapobject"}) +} diff --git a/server/mapobject/setup.go b/server/mapobject/setup.go index f12c801..37bb20b 100644 --- a/server/mapobject/setup.go +++ b/server/mapobject/setup.go @@ -5,6 +5,8 @@ import ( "mapserver/eventbus" "mapserver/mapblockparser" "mapserver/mapobjectdb" + + "github.com/sirupsen/logrus" ) type MapObjectListener interface { @@ -44,6 +46,16 @@ func (this *Listener) OnEvent(eventtype string, o interface{}) { for z := 0; z < 16; z++ { nodeid := block.GetNodeId(x, y, z) if nodeid == id { + fields := logrus.Fields{ + "mbpos": block.Pos, + "x": x, + "y": y, + "z": z, + "type": name, + "nodeid": nodeid, + } + log.WithFields(fields).Debug("OnEvent()") + obj := v.onMapObject(x, y, z, block) if obj != nil { diff --git a/server/mapobjectdb/accessor.go b/server/mapobjectdb/accessor.go index e47eed3..c78c292 100644 --- a/server/mapobjectdb/accessor.go +++ b/server/mapobjectdb/accessor.go @@ -3,6 +3,8 @@ package mapobjectdb import ( "mapserver/coords" "time" + + "github.com/sirupsen/logrus" ) /* @@ -33,9 +35,14 @@ type MapObject struct { func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject { - if x > 16 || y > 16 || z > 16 { - panic("Out of range3!") //XXX + fields := logrus.Fields{ + "mbpos": MBPos, + "x": x, + "y": y, + "z": z, + "type": _type, } + log.WithFields(fields).Debug("NewMapObject") o := MapObject{ MBPos: MBPos, @@ -54,7 +61,7 @@ type SearchQuery struct { //mapblock position Pos1 *coords.MapBlockCoords `json:"pos1"` Pos2 *coords.MapBlockCoords `json:"pos2"` - Type string `json:"type"` + Type string `json:"type"` } type DBAccessor interface { diff --git a/server/mapobjectdb/logger.go b/server/mapobjectdb/logger.go new file mode 100644 index 0000000..3dbcf6a --- /dev/null +++ b/server/mapobjectdb/logger.go @@ -0,0 +1,11 @@ +package mapobjectdb + +import ( + "github.com/sirupsen/logrus" +) + +var log *logrus.Entry + +func init() { + log = logrus.WithFields(logrus.Fields{"prefix": "mapobjectdb"}) +} diff --git a/server/mapobjectdb/sqlite/mapobjects.go b/server/mapobjectdb/sqlite/mapobjects.go index 2ce1298..d2e3a2d 100644 --- a/server/mapobjectdb/sqlite/mapobjects.go +++ b/server/mapobjectdb/sqlite/mapobjects.go @@ -5,7 +5,6 @@ import ( "mapserver/mapobjectdb" ) - func (db *Sqlite3Accessor) GetMapData(q mapobjectdb.SearchQuery) ([]*mapobjectdb.MapObject, error) { rows, err := db.db.Query(getMapDataPosQuery, q.Type, @@ -42,11 +41,15 @@ func (db *Sqlite3Accessor) GetMapData(q mapobjectdb.SearchQuery) ([]*mapobjectdb if currentId == nil || *currentId != id { pos := coords.NewMapBlockCoords(posx, posy, posz) - mo := mapobjectdb.NewMapObject( - pos, - x, y, z, - Type, - ) + mo := &mapobjectdb.MapObject{ + MBPos: pos, + Type: Type, + X: x, + Y: y, + Z: z, + Mtime: mtime, + Attributes: make(map[string]string), + } currentObj = mo currentId = &id @@ -66,7 +69,6 @@ func (db *Sqlite3Accessor) RemoveMapData(pos *coords.MapBlockCoords) error { return err } - func (db *Sqlite3Accessor) AddMapData(data *mapobjectdb.MapObject) error { res, err := db.db.Exec(addMapDataQuery, data.X, data.Y, data.Z,