Skip to content

Commit

Permalink
## [3.4.0-beta.3] - 2022-06-09
Browse files Browse the repository at this point in the history
### Changed
- Optimized log color
  • Loading branch information
k8w committed Jun 8, 2022
1 parent a903a8c commit a4f492c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# CHANGELOG

## [3.4.0-beta.2] - 2022-06-08
## [3.4.0-beta.3] - 2022-06-09
### Added
- `https` options for `HttpServer`
- `wss` options for `WsServer`
- Support using the same name with API and message
### Changed
- Deprecate `serviceName` in `preRecvDataFlow`, use `serviceId` instead
- Optimized log color

## [3.3.3] - 2022-06-07
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsrpc",
"version": "3.4.0-beta.2",
"version": "3.4.0-beta.3",
"description": "A TypeScript RPC Framework, with runtime type checking and built-in serialization, support both HTTP and WebSocket.",
"main": "index.js",
"exports": {
Expand Down
9 changes: 5 additions & 4 deletions src/server/base/ApiCall.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from 'chalk';
import { TSBuffer } from 'tsbuffer';
import { ApiService, TransportDataUtil } from "tsrpc-base-client";
import { ApiReturn, BaseServiceType, ServerOutputData, TsrpcError, TsrpcErrorData, TsrpcErrorType } from "tsrpc-proto";
Expand Down Expand Up @@ -41,7 +42,7 @@ export abstract class ApiCall<Req = any, Res = any, ServiceType extends BaseServ
constructor(options: ApiCallOptions<Req, ServiceType>, logger?: PrefixLogger) {
super(options, logger ?? new PrefixLogger({
logger: options.conn.logger,
prefixs: [`[Api:${options.service.name}]${options.sn !== undefined ? ` SN=${options.sn}` : ''}`]
prefixs: [`${chalk.cyan.underline(`[Api:${options.service.name}]`)}${options.sn !== undefined ? chalk.gray(` SN=${options.sn}`) : ''}`]
}));

this.sn = options.sn;
Expand Down Expand Up @@ -108,14 +109,14 @@ export abstract class ApiCall<Req = any, Res = any, ServiceType extends BaseServ
// record & log ret
this._usedTime = Date.now() - this.startTime;
if (ret.isSucc) {
this.logger.log('[ApiRes]', `${this.usedTime}ms`, this.server.options.logResBody ? ret.res : '');
this.logger.log(chalk.green('[ApiRes]'), `${this.usedTime}ms`, this.server.options.logResBody ? ret.res : '');
}
else {
if (ret.err.type === TsrpcErrorType.ApiError) {
this.logger.log('[ApiErr]', `${this.usedTime}ms`, ret.err, 'req=', this.req);
this.logger.log(chalk.red('[ApiErr]'), `${this.usedTime}ms`, ret.err, 'req=', this.req);
}
else {
this.logger.error(`[ApiErr]`, `${this.usedTime}ms`, ret.err, 'req=', this.req)
this.logger.error(chalk.red('[ApiErr]'), `${this.usedTime}ms`, ret.err, 'req=', this.req)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/server/base/BaseConnection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from "chalk";
import { MsgHandlerManager, ParsedServerInput, TransportDataUtil } from "tsrpc-base-client";
import { BaseServiceType } from "tsrpc-proto";
import { PrefixLogger } from "../models/PrefixLogger";
Expand Down Expand Up @@ -128,7 +129,7 @@ export abstract class BaseConnection<ServiceType extends BaseServiceType = any>
}

// Do send!
this.server.options.logMsg && this.logger.log('[SendMsg]', `[${msgName}]`, msg);
this.server.options.logMsg && this.logger.log(chalk.cyan.underline(`[Msg:${msgName}]`), chalk.green('[SendMsg]'), msg);
let opSend = await this.sendData(opServerOutput.output);
if (!opSend.isSucc) {
return opSend;
Expand Down
2 changes: 1 addition & 1 deletion src/server/base/BaseServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export abstract class BaseServer<ServiceType extends BaseServiceType = BaseServi
call = preFlow;

// MsgHandler
this.options.logMsg && call.logger.log('[RecvMsg]', call.msg);
this.options.logMsg && call.logger.log(chalk.green('[RecvMsg]'), call.msg);
let promises = [
// Conn Handlers
...(call.conn['_msgHandlers']?.forEachHandler(call.service.name, call.logger, call) ?? []),
Expand Down
3 changes: 2 additions & 1 deletion src/server/base/MsgCall.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from "chalk";
import { MsgService } from "tsrpc-base-client";
import { BaseServiceType } from "tsrpc-proto";
import { PrefixLogger } from "../models/PrefixLogger";
Expand All @@ -22,7 +23,7 @@ export abstract class MsgCall<Msg = any, ServiceType extends BaseServiceType = a
constructor(options: MsgCallOptions<Msg, ServiceType>, logger?: PrefixLogger) {
super(options, logger ?? new PrefixLogger({
logger: options.conn.logger,
prefixs: [`[Msg:${options.service.name}]`]
prefixs: [chalk.cyan.underline(`[Msg:${options.service.name}]`)]
}));

this.msg = options.msg;
Expand Down
3 changes: 2 additions & 1 deletion src/server/http/HttpConnection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from "chalk";
import * as http from "http";
import { ParsedServerInput } from "tsrpc-base-client";
import { BaseServiceType } from "tsrpc-proto";
Expand Down Expand Up @@ -37,7 +38,7 @@ export class HttpConnection<ServiceType extends BaseServiceType = any> extends B
constructor(options: HttpConnectionOptions<ServiceType>) {
super(options, new PrefixLogger({
logger: options.server.logger,
prefixs: [`${options.ip} #${options.id}`]
prefixs: [chalk.gray(`${options.ip} #${options.id}`)]
}));

this.httpReq = options.httpReq;
Expand Down
3 changes: 2 additions & 1 deletion src/server/inner/InnerConnection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from "chalk";
import { ApiReturn, TsrpcError, TsrpcErrorType } from "tsrpc-proto";
import { ApiCall, BaseConnection, BaseServiceType, PrefixLogger, TransportDataUtil } from "../..";
import { BaseConnectionOptions, ConnectionStatus } from "../base/BaseConnection";
Expand Down Expand Up @@ -27,7 +28,7 @@ export class InnerConnection<ServiceType extends BaseServiceType = any> extends
constructor(options: InnerConnectionOptions<ServiceType>) {
super(options, new PrefixLogger({
logger: options.server.logger,
prefixs: [`Inner #${options.id}`]
prefixs: [chalk.gray(`Inner #${options.id}`)]
}));

this.return = options.return;
Expand Down
3 changes: 2 additions & 1 deletion src/server/ws/WsConnection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from "chalk";
import * as http from "http";
import { TransportDataUtil } from "tsrpc-base-client";
import { BaseServiceType } from "tsrpc-proto";
Expand Down Expand Up @@ -36,7 +37,7 @@ export class WsConnection<ServiceType extends BaseServiceType = any> extends Bas
constructor(options: WsConnectionOptions<ServiceType>) {
super(options, new PrefixLogger({
logger: options.server.logger,
prefixs: [`${options.ip} Conn#${options.id}`]
prefixs: [chalk.gray(`${options.ip} Conn#${options.id}`)]
}));
this.ws = options.ws;
this.httpReq = options.httpReq;
Expand Down

0 comments on commit a4f492c

Please sign in to comment.