Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log level #153

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet-service",
"version": "0.23.2",
"version": "0.23.3",
"description": "Puppet Service for Wechaty",
"main": "dist/src/mod.js",
"typings": "dist/src/mod.d.ts",
Expand Down
26 changes: 13 additions & 13 deletions src/client/puppet-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class PuppetService extends Puppet {
private async discoverServiceIp (
token: string,
): Promise<{ ip?: string, port?: number }> {
log.verbose('PuppetService', 'discoverServiceIp(%s)', token)
log.info('PuppetService', 'discoverServiceIp(%s)', token)

const chatieEndpoint = GET_WECHATY_SERVICE_DISCOVERY_ENDPOINT()

Expand Down Expand Up @@ -243,7 +243,7 @@ export class PuppetService extends Puppet {
}

protected async startGrpcClient (): Promise<void> {
log.verbose('PuppetService', 'startGrpcClient()')
log.info('PuppetService', 'startGrpcClient()')

if (this.grpcClient) {
throw new Error('puppetClient had already initialized')
Expand Down Expand Up @@ -279,7 +279,7 @@ export class PuppetService extends Puppet {
}

protected async stopGrpcClient (): Promise<void> {
log.verbose('PuppetService', 'stopGrpcClient()')
log.info('PuppetService', 'stopGrpcClient()')

if (!this.grpcClient) {
throw new Error('puppetClient had not initialized')
Expand All @@ -291,7 +291,7 @@ export class PuppetService extends Puppet {

override async start (): Promise<void> {
await super.start()
log.verbose('PuppetService', 'start()')
log.info('PuppetService', 'start()')

if (!this.options.token) {
const tokenNotFoundError = 'wechaty-puppet-service: WECHATY_PUPPET_SERVICE_TOKEN not found'
Expand Down Expand Up @@ -359,7 +359,7 @@ export class PuppetService extends Puppet {

override async stop (): Promise<void> {
await super.stop()
log.verbose('PuppetService', 'stop()')
log.info('PuppetService', 'stop()')

if (this.state.off()) {
log.warn('PuppetService', 'stop() is called on a OFF puppet. await ready(off) and return.')
Expand Down Expand Up @@ -413,7 +413,7 @@ export class PuppetService extends Puppet {
}

private async startGrpcStream (): Promise<void> {
log.verbose('PuppetService', 'startGrpcStream()')
log.info('PuppetService', 'startGrpcStream()')

if (this.eventStream) {
throw new Error('event stream exists')
Expand All @@ -425,7 +425,7 @@ export class PuppetService extends Puppet {
this.eventStream = this.grpcClient!.event(new EventRequest())
} catch (e) {
if (retry-- > 0) {
log.verbose('PuppetService', `startGrpcStream() connection failed, ${retry} retries left, reconnecting in 2 seconds...`)
log.warn('PuppetService', `startGrpcStream() connection failed, ${retry} retries left, reconnecting in 2 seconds...`)
await new Promise<void>(resolve => setTimeout(resolve, 2 * 1000))
} else {
log.error('PuppetService', `startGrpcStream() connection failed and max retries has been reached. Error:\n${e.stack}`)
Expand All @@ -442,11 +442,11 @@ export class PuppetService extends Puppet {
this.eventStream
.on('data', this.onGrpcStreamEvent.bind(this))
.on('end', () => {
log.verbose('PuppetService', 'startGrpcStream() eventStream.on(end)')
log.info('PuppetService', 'startGrpcStream() eventStream.on(end)')
})
.on('error', (e: unknown) => {
// https://github.com/wechaty/wechaty-puppet-service/issues/16
log.verbose('PuppetService', 'startGrpcStream() eventStream.on(error) %s', e)
log.error('PuppetService', 'startGrpcStream() eventStream.on(error) %s', e)
const reason = 'startGrpcStream() eventStream.on(error) ' + e
/**
* The `Puppet` class have a throttleQueue for receiving the `reset` events
Expand All @@ -455,13 +455,13 @@ export class PuppetService extends Puppet {
this.emit('reset', { data: reason })
})
.on('cancel', (...args: any[]) => {
log.verbose('PuppetService', 'startGrpcStream() eventStream.on(cancel), %s', JSON.stringify(args))
log.info('PuppetService', 'startGrpcStream() eventStream.on(cancel), %s', JSON.stringify(args))
})

}

private async grpcClientStart (): Promise<void> {
log.verbose('PuppetService', 'grpcClientStart()')
log.info('PuppetService', 'grpcClientStart()')

try {
await util.promisify(
Expand Down Expand Up @@ -560,7 +560,7 @@ export class PuppetService extends Puppet {
}

private stopGrpcStream (): void {
log.verbose('PuppetService', 'stopGrpcStream()')
log.info('PuppetService', 'stopGrpcStream()')

if (!this.eventStream) {
log.verbose('PuppetService', 'no eventStream when stop, skip destroy.')
Expand All @@ -579,7 +579,7 @@ export class PuppetService extends Puppet {
}

override async logout (): Promise<void> {
log.verbose('PuppetService', 'logout()')
log.info('PuppetService', 'logout()')

if (!this.id) {
throw new Error('logout before login?')
Expand Down
6 changes: 3 additions & 3 deletions src/server/event-stream-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class EventStreamManager {
public start (
stream: grpc.ServerWritableStream<EventRequest, EventResponse>,
): void {
log.verbose('EventStreamManager', 'start(stream)')
log.info('EventStreamManager', 'start(stream)')

if (this.eventStream) {
throw new Error('can not set twice')
Expand All @@ -78,7 +78,7 @@ export class EventStreamManager {
}

public stop (): void {
log.verbose('EventStreamManager', 'stop()')
log.info('EventStreamManager', 'stop()')

if (!this.eventStream) {
throw new Error('no this.eventStream')
Expand All @@ -92,7 +92,7 @@ export class EventStreamManager {
type : EventTypeMap[keyof EventTypeMap], // https://stackoverflow.com/a/49286056/1123955
obj : object,
): void {
log.verbose('EventStreamManager', 'grpcEmit(%s[%s], %s)',
log.info('EventStreamManager', 'grpcEmit(%s[%s], %s)',
EventTypeRev[type],
type,
JSON.stringify(obj),
Expand Down
4 changes: 2 additions & 2 deletions src/server/puppet-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ export function puppetImplementation (
},

start: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'start()')
log.info('PuppetServiceImpl', 'start()')
void call

try {
Expand All @@ -1237,7 +1237,7 @@ export function puppetImplementation (
},

stop: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'stop()')
log.info('PuppetServiceImpl', 'stop()')
void call

try {
Expand Down
6 changes: 3 additions & 3 deletions src/server/puppet-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class PuppetServer {
constructor (
public readonly options: PuppetServerOptions,
) {
log.verbose('PuppetServer',
log.info('PuppetServer',
'constructor({endpoint: "%s", puppet: "%s", token: "%s"})',
options.endpoint,
options.puppet,
Expand All @@ -45,7 +45,7 @@ export class PuppetServer {
}

public async start (): Promise<void> {
log.verbose('PuppetServer', 'start()')
log.info('PuppetServer', 'start()')

if (this.grpcServer) {
throw new Error('grpc server existed!')
Expand Down Expand Up @@ -75,7 +75,7 @@ export class PuppetServer {
}

public async stop (): Promise<void> {
log.verbose('PuppetServer', 'stop()')
log.info('PuppetServer', 'stop()')

if (!this.grpcServer) {
throw new Error('no grpc server')
Expand Down