Skip to content

Commit

Permalink
chore: update logger debug
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 11, 2023
1 parent 7d21997 commit 17b5788
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions adapters/dingtalk/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export class HttpServer extends Adapter<DingtalkBot> {

if (computedSign !== sign) return ctx.status = 403
const body = ctx.request.body as Message
this.logger.debug(require('util').inspect(body, false, null, true))
this.logger.debug(body)
const session = await decodeMessage(bot, body)
this.logger.debug(require('util').inspect(session, false, null, true))
this.logger.debug(session)
if (session) bot.dispatch(session)
})
}
Expand Down
6 changes: 3 additions & 3 deletions adapters/dingtalk/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class WsClient extends Adapter.WsClient<DingtalkBot> {
this.bot.online()
this.socket.addEventListener('message', async ({ data }) => {
const parsed = JSON.parse(data.toString())
this.ctx.logger('dingtalk').debug(require('util').inspect(parsed, false, null, true))
this.ctx.logger('dingtalk').debug(parsed)
if (parsed.type === 'SYSTEM') {
if (parsed.headers.topic === 'ping') {
this.socket.send(JSON.stringify({
Expand All @@ -37,10 +37,10 @@ export class WsClient extends Adapter.WsClient<DingtalkBot> {
}))
}
} else if (parsed.type === 'CALLBACK') {
this.ctx.logger('dingtalk').debug(require('util').inspect(JSON.parse(parsed.data), false, null, true))
this.ctx.logger('dingtalk').debug(JSON.parse(parsed.data))
const session = await decodeMessage(this.bot, JSON.parse(parsed.data))
if (session) this.bot.dispatch(session)
this.ctx.logger('dingtalk').debug(require('util').inspect(session, false, null, true))
this.ctx.logger('dingtalk').debug(session)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/discord/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Context, Fragment, h, isNullable, Logger, Quester, Schema, Universal } from '@satorijs/satori'
import { Bot, Context, Fragment, h, Logger, Quester, Schema, Universal } from '@satorijs/satori'
import * as Discord from './utils'
import { DiscordMessageEncoder } from './message'
import { Internal, Webhook } from './types'
Expand Down
5 changes: 4 additions & 1 deletion adapters/discord/src/types/internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Dict, makeArray, Quester } from '@satorijs/satori'
import { Dict, Logger, makeArray, Quester } from '@satorijs/satori'

const logger = new Logger('discord')

export class Internal {
constructor(private http: Quester) {}
Expand Down Expand Up @@ -28,6 +30,7 @@ export class Internal {
throw new Error(`too many arguments for ${path}, received ${raw}`)
}
try {
logger.debug(`${method} ${url}`, config)
return await this.http(method, url, config)
} catch (error) {
if (!Quester.isAxiosError(error) || !error.response) throw error
Expand Down
2 changes: 1 addition & 1 deletion adapters/discord/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class WsClient extends Adapter.WsClient<DiscordBot> {
} catch (error) {
return logger.warn('cannot parse message', data)
}
logger.debug(require('util').inspect(parsed, false, null, true))
logger.debug(parsed)
if (parsed.s) {
this._d = parsed.s
}
Expand Down
4 changes: 2 additions & 2 deletions adapters/line/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class HttpServer extends Adapter<LineBot> {
if (hash !== sign) {
return ctx.status = 403
}
this.logger.debug(require('util').inspect(parsed, false, null, true))
this.logger.debug(parsed)
for (const event of parsed.events) {
const sessions = await adaptSessions(bot, event)
if (sessions.length) sessions.forEach(bot.dispatch.bind(bot))
this.logger.debug(require('util').inspect(sessions, false, null, true))
this.logger.debug(sessions)
}
ctx.status = 200
ctx.body = 'ok'
Expand Down
2 changes: 1 addition & 1 deletion adapters/qq/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class QQGuildMessageEncoder extends MessageEncoder<QQGuildBot> {
}
}

this.bot.ctx.logger('qq').debug(require('util').inspect(r, false, null, true))
this.bot.ctx.logger('qq').debug(r)
const session = this.bot.session()
session.type = 'send'
// await decodeMessage(this.bot, r, session.event.message = {}, session.event)
Expand Down
4 changes: 2 additions & 2 deletions adapters/qq/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class WsClient extends Adapter.WsClient<QQBot> {
async accept() {
this.socket.addEventListener('message', async ({ data }) => {
const parsed: Payload = JSON.parse(data.toString())
logger.debug(require('util').inspect(parsed, false, null, true))
logger.debug(parsed)
if (parsed.op === Opcode.HELLO) {
const token = await this.bot.getAccessToken()
if (this._sessionId) {
Expand Down Expand Up @@ -79,7 +79,7 @@ export class WsClient extends Adapter.WsClient<QQBot> {
}
const session = await adaptSession(this.bot, parsed)
if (session) this.bot.dispatch(session)
logger.debug(require('util').inspect(session, false, null, true))
logger.debug(session)
}
})

Expand Down
4 changes: 2 additions & 2 deletions adapters/slack/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export class HttpServer extends Adapter<SlackBot> {
ctx.status = 200
ctx.body = 'ok'
const payload: EnvelopedEvent<SlackEvent> = ctx.request.body
this.logger.debug(require('util').inspect(payload, false, null, true))
this.logger.debug(payload)
const session = await adaptSession(bot, payload)
this.logger.debug(require('util').inspect(session, false, null, true))
this.logger.debug(session)
if (session) bot.dispatch(session)
}
})
Expand Down
4 changes: 2 additions & 2 deletions adapters/slack/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class WsClient extends Adapter.WsClient<SlackBot<SlackBot.BaseConfig & Ws
async accept() {
this.socket.addEventListener('message', async ({ data }) => {
const parsed: SocketEvent = JSON.parse(data.toString())
logger.debug(require('util').inspect(parsed, false, null, true))
logger.debug(parsed)
const { type } = parsed
if (type === 'hello') {
// @ts-ignore
Expand All @@ -32,7 +32,7 @@ export class WsClient extends Adapter.WsClient<SlackBot<SlackBot.BaseConfig & Ws

if (session) {
this.bot.dispatch(session)
logger.debug(require('util').inspect(session, false, null, true))
logger.debug(session)
}
}
})
Expand Down
6 changes: 3 additions & 3 deletions adapters/wechat-official/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export class HttpServer extends Adapter<WechatOfficialBot> {
const { xml: data2 } = await xml2js.parseStringPromise(message, {
explicitArray: false,
})
bot.logger.debug('decrypted %c', require('util').inspect(data2, false, null, true))
bot.logger.debug('decrypted %c', data2)
data = data2
}

bot.logger.debug('%c', require('util').inspect(ctx.request.rawBody, false, null, true))
bot.logger.debug('%c', ctx.request.rawBody)

const session = await decodeMessage(localBot, data)

Expand All @@ -73,7 +73,7 @@ export class HttpServer extends Adapter<WechatOfficialBot> {
if (session) {
session.wechatOfficialResolve = resolveFunction
localBot.dispatch(session)
// localBot.logger.debug(require('util').inspect(session, false, null, true))
// localBot.logger.debug(session)
}
try {
const result: any = await promise
Expand Down
6 changes: 3 additions & 3 deletions adapters/wecom/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ export class HttpServer extends Adapter<WecomBot> {
const { xml: data2 } = await xml2js.parseStringPromise(message, {
explicitArray: false,
})
bot.logger.debug('decrypted %c', require('util').inspect(data2, false, null, true))
bot.logger.debug('decrypted %c', data2)
data = data2
}

bot.logger.debug('%c', require('util').inspect(ctx.request.rawBody, false, null, true))
bot.logger.debug('%c', ctx.request.rawBody)

const session = await decodeMessage(localBot, data)
if (session) {
localBot.dispatch(session)
localBot.logger.debug(require('util').inspect(session, false, null, true))
localBot.logger.debug(session)
}
ctx.status = 200
ctx.body = 'success'
Expand Down
6 changes: 3 additions & 3 deletions adapters/whatsapp/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HttpServer {
if (!adapters.length) return ctx.status = 403

const parsed = ctx.request.body as WebhookBody
this.logger.debug(require('util').inspect(parsed, false, null, true))
this.logger.debug(parsed)
ctx.body = 'ok'
ctx.status = 200
if (parsed.object !== 'whatsapp_business_account') return
Expand All @@ -38,12 +38,12 @@ class HttpServer {
const session = await decodeMessage(bot, entry)
if (session.length) session.forEach(bot.dispatch.bind(bot))
this.logger.debug('handling bot: %s', bot.sid)
this.logger.debug(require('util').inspect(session, false, null, true))
this.logger.debug(session)
}
})

ctx.router.get('/whatsapp', async (ctx) => {
this.logger.debug(require('util').inspect(ctx.query, false, null, true))
this.logger.debug(ctx.query)
const verifyToken = ctx.query['hub.verify_token']
const challenge = ctx.query['hub.challenge']
for (const adapter of this.adapters) {
Expand Down

0 comments on commit 17b5788

Please sign in to comment.