onrik / logrus

Hooks for logrus logging
MIT License
122 stars 30 forks source link

support logs with with fields and `_source` #13

Open xmlking opened 5 years ago

xmlking commented 5 years ago

With _source="registry/container.go:93" we can pinpoint source of the SQL logs

current logs with fields only

DEBU[2019-08-13T10:51:32-07:00] CREATE TABLE "users" ("created_at" datetime NOT NULL,"deleted_at" datetime,"email" varchar(255) NOT NULL,"first_name" varchar(255) NOT NULL,"id" uuid,"last_name" varchar(255) NOT NULL,"updated_at" datetime NOT NULL,"username" varchar(100) NOT NULL , PRIMARY KEY ("id")) [190.156µs]  module=gorm
DEBU[2019-08-13T10:51:32-07:00] CREATE INDEX idx_users_deleted_at ON "users"(deleted_at)  [76.138µs]  module=gorm
DEBU[2019-08-13T10:51:32-07:00] CREATE TABLE "profiles" ("avatar" varchar(255),"birthday" datetime NOT NULL,"created_at" datetime NOT NULL,"deleted_at" datetime,"gender" varchar(255),"id" uuid,"tz" varchar(255),"updated_at" datetime NOT NULL,"user_id" varchar(255) , PRIMARY KEY ("id")) [80.66µs]  module=gorm
DEBU[2019-08-13T10:51:32-07:00] CREATE INDEX idx_profiles_deleted_at ON "profiles"(deleted_at)  [65.971µs]  module=gorm

logs with with fields and _source

DEBU[2019-08-13T10:53:23-07:00] CREATE TABLE "users" ("created_at" datetime NOT NULL,"deleted_at" datetime,"email" varchar(255) NOT NULL,"first_name" varchar(255) NOT NULL,"id" uuid,"last_name" varchar(255) NOT NULL,"updated_at" datetime NOT NULL,"username" varchar(100) NOT NULL , PRIMARY KEY ("id"))  _source="registry/container.go:93" module=gorm type=sql
DEBU[2019-08-13T10:53:23-07:00] CREATE INDEX idx_users_deleted_at ON "users"(deleted_at)   _source="registry/container.go:93" module=gorm type=sql
DEBU[2019-08-13T10:53:23-07:00] CREATE TABLE "profiles" ("avatar" varchar(255),"birthday" datetime NOT NULL,"created_at" datetime NOT NULL,"deleted_at" datetime,"gender" varchar(255),"id" uuid,"tz" varchar(255),"updated_at" datetime NOT NULL,"user_id" varchar(255) , PRIMARY KEY ("id"))  _source="registry/container.go:99" module=gorm type=sql
DEBU[2019-08-13T10:53:23-07:00] CREATE INDEX idx_profiles_deleted_at ON "profiles"(deleted_at)   _source="registry/container.go:99" module=gorm type=sql