Skip to content

Commit

Permalink
feat(core): optimize logs for adapter.wsclient
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 12, 2021
1 parent 7e19539 commit 959fa2b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
6 changes: 4 additions & 2 deletions packages/koishi-core/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export namespace Adapter {
logger.debug('websocket client opening')
bot.status = Bot.Status.CONNECTING
const socket = await this.prepare(bot)
const url = socket.url.replace(/\?.+/, '')

socket.on('error', error => logger.debug(error))

Expand All @@ -126,7 +127,8 @@ export namespace Adapter {
logger.debug(`websocket closed with ${code}`)
if (!this._listening) return

const message = reason || `failed to connect to ${socket.url}`
// remove query args to protect privacy
const message = reason || `failed to connect to ${url}`
let timeout = retryInterval
if (_retryCount >= retryTimes) {
if (this.app.status === App.Status.open) {
Expand All @@ -146,7 +148,7 @@ export namespace Adapter {
socket.on('open', () => {
_retryCount = 0
bot.socket = socket
logger.debug('connect to ws server:', socket.url)
logger.info('connect to ws server:', url)
this.connect(bot).then(() => {
bot.status = Bot.Status.GOOD
resolve()
Expand Down
11 changes: 1 addition & 10 deletions packages/plugin-eval/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,8 @@ export class EvalWorker {
})
}

addSetupFile(name: string, filename: string) {
if (this.config.setupFiles[name] === filename) return
const ctx = this[Context.current]
this.config.setupFiles[name] = filename
ctx.before('disconnect', () => {
delete this.config.setupFiles[name]
})
}

// delegated class methods which use instance properties
// should be written in arrow functions
// should be written in arrow functions to ensure accessibility
start = async () => {
this.state = State.opening
await this.ctx.parallel('eval/before-start')
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-eval/src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class WorkerHandle {
async sync(scope: Scope) {
await scope.user?._update()
await scope.channel?._update()
const buffer = serialize(storage)
const buffer = serialize(scope.storage)
await safeWriteFile(storagePath, buffer)
}

Expand Down

0 comments on commit 959fa2b

Please sign in to comment.