feat: improve log message

This commit is contained in:
fantasticit 2022-04-25 09:19:48 +08:00
parent 5f56dc0448
commit 8f9cecf277
3 changed files with 19 additions and 14 deletions

View File

@ -20,8 +20,7 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe()); app.useGlobalPipes(new ValidationPipe());
app.setGlobalPrefix(config.get('server.prefix') || '/'); app.setGlobalPrefix(config.get('server.prefix') || '/');
await app.listen(config.get('server.port') || 4000); await app.listen(config.get('server.port') || 4000);
const url = await app.getUrl(); console.log('[think] 主服务启动成功');
console.log('服务启动成功:', url);
} }
bootstrap(); bootstrap();

View File

@ -63,14 +63,20 @@ export class CollaborationService {
} }
private async initServer() { private async initServer() {
try {
const server = Server.configure({ const server = Server.configure({
quiet: true,
onAuthenticate: this.onAuthenticate.bind(this), onAuthenticate: this.onAuthenticate.bind(this),
onLoadDocument: this.onLoadDocument.bind(this), onLoadDocument: this.onLoadDocument.bind(this),
onChange: this.onChange.bind(this), onChange: this.onChange.bind(this),
onDisconnect: this.onDisconnect.bind(this), onDisconnect: this.onDisconnect.bind(this),
}); });
this.server = server; this.server = server;
this.server.listen(lodash.get(getConfig(), 'server.collaborationPort', 5003)); await this.server.listen(lodash.get(getConfig(), 'server.collaborationPort', 5003));
console.log('[think] 协作服务启动成功');
} catch (err) {
console.error('[think] 协作服务启动失败:', err.message);
}
} }
async onAuthenticate({ connection, token, requestParameters }: onAuthenticatePayload) { async onAuthenticate({ connection, token, requestParameters }: onAuthenticatePayload) {

View File

@ -10,7 +10,7 @@ type VerisonDataItem = { version: string; data: string };
export class DocumentVersionService { export class DocumentVersionService {
private redis: Redis; private redis: Redis;
private max: number = 0; private max: number = 0;
private error: string | null = '文档版本服务启动中'; private error: string | null = '[think] 文档版本服务启动中';
constructor() { constructor() {
this.init(); this.init();
@ -41,16 +41,16 @@ export class DocumentVersionService {
lazyConnect: true, lazyConnect: true,
}); });
redis.on('ready', () => { redis.on('ready', () => {
console.log('文档版本服务启动成功'); console.log('[think] 文档版本服务启动成功');
this.redis = redis; this.redis = redis;
this.error = null; this.error = null;
}); });
redis.on('error', (e) => { redis.on('error', (e) => {
console.error(`Redis 启动失败: "${e}"`); console.error(`[think] Redis 启动失败: "${e}"`);
}); });
redis.connect().catch((e) => { redis.connect().catch((e) => {
this.redis = null; this.redis = null;
this.error = 'Redis 启动失败:无法提供文档版本服务'; this.error = '[think] Redis 启动失败:无法提供文档版本服务';
}); });
} catch (e) {} } catch (e) {}
} }