Skip to content

Commit

Permalink
chore: attach log level to exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 13, 2020
1 parent 750b1d1 commit a17867b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/koishi-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from 'koishi-core'
export * from 'koishi-utils'
export { AppConfig } from './worker'

const { version } = require('../package')
export { version }
2 changes: 0 additions & 2 deletions packages/koishi-cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ function createWorker () {
child.on('message', (data: any) => {
if (data.type === 'start') {
started = true
} else if (data.type === 'error') {
logger.error(data.message)
}
})

Expand Down
20 changes: 8 additions & 12 deletions packages/koishi-cli/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { safeLoad } from 'js-yaml'

const { version } = require('../package')

let baseLogLevel = 3
if (process.env.KOISHI_LOG_LEVEL !== undefined) {
baseLogLevel = +process.env.KOISHI_LOG_LEVEL
}

process.on('uncaughtException', ({ message }) => {
process.send({
type: 'error',
message,
}, () => {
process.exit(-1)
})
logger.error(message, baseLogLevel)
process.exit(-1)
})

const cwd = process.cwd()
Expand Down Expand Up @@ -98,11 +99,6 @@ if (['.js', '.json'].includes(extension)) {

if (!config) throw new Error('config file not found.')

let baseLogLevel = 3
if (process.env.KOISHI_LOG_LEVEL !== undefined) {
baseLogLevel = +process.env.KOISHI_LOG_LEVEL
}

if (Array.isArray(config)) {
config.forEach(conf => prepareApp(conf))
} else {
Expand Down Expand Up @@ -150,6 +146,6 @@ appList.forEach((app) => {
})

startAll().catch((error) => {
logger.error(error)
logger.error(error, baseLogLevel)
process.exit(-1)
})

0 comments on commit a17867b

Please sign in to comment.