forked from Imfdj/egg-beehive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 增加app.logger.errorAndSentry,记录error并在prod环境下发送sentry;
增加app.logger.errorAndSentry,记录error并在prod环境下发送sentry;
- Loading branch information
Showing
7 changed files
with
27 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ const dayjs = require('dayjs'); | |
const path = require('path'); | ||
const fs = require('fs'); | ||
const { permissionsToRedis } = require('./app-boot-hook-do'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
class AppBootHook { | ||
constructor(app) { | ||
|
@@ -45,6 +46,15 @@ class AppBootHook { | |
|
||
// 例如:从数据库加载数据到内存缓存 | ||
// this.app.cacheData = await this.app.model.query(QUERY_CACHE_SQL); | ||
|
||
Sentry.init({ | ||
dsn: 'http://[email protected]/4', | ||
}); | ||
// logger记录error并在prod环境下发送错误到Sentry | ||
this.app.logger.errorAndSentry = (msg, ...arg) => { | ||
this.app.config.env === 'prod' ? Sentry.captureException(msg) : null; | ||
this.app.logger.error(msg, ...arg); | ||
}; | ||
this.app.lodash = lodash; | ||
this.app.uuidv4 = uuidv4; | ||
this.app.dayjs = dayjs; | ||
|
@@ -54,16 +64,8 @@ class AppBootHook { | |
// 资源数据缓存到redis | ||
await permissionsToRedis(this.app); | ||
|
||
Sequelize.addHook('beforeValidate', (permission, options) => { | ||
// 做些什么 | ||
}); | ||
Sequelize.addHook('afterBulkUpdate', options => { | ||
console.log(2222222); | ||
console.log(options); | ||
}); | ||
Sequelize.addHook('afterSave', (permission, options) => { | ||
console.log(333333); | ||
console.log(permission); | ||
// 做些什么 | ||
}); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,5 @@ | ||
'use strict'; | ||
const Sentry = require('@sentry/node'); | ||
// const Tracing = require("@sentry/tracing"); | ||
Sentry.init({ | ||
// dsn: "https://[email protected]/5553058", | ||
dsn: 'http://[email protected]/4', | ||
|
||
// We recommend adjusting this value in production, or using tracesSampler | ||
// for finer control | ||
// tracesSampleRate: 1.0, | ||
}); | ||
// const transaction = Sentry.startTransaction({ | ||
// op: "test", | ||
// name: "My First Test Transaction", | ||
// }); | ||
module.exports = (option, app) => { | ||
return async function(ctx, next) { | ||
try { | ||
|
@@ -49,8 +36,7 @@ module.exports = (option, app) => { | |
}; | ||
ctx.helper.body.VALIDATION_FAILED({ ctx, res }); | ||
} else { | ||
app.config.env === 'prod' ? Sentry.captureException(err) : null; | ||
// transaction.finish(); | ||
app.logger.errorAndSentry(err); | ||
} | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters