Skip to content

Commit

Permalink
fix(logging): replace TransformableInfo with ITransformableInfo type (#…
Browse files Browse the repository at this point in the history
…994)

* fix(logging): ITransformableInfo type

* add license at top of mock test data
  • Loading branch information
TarikGul committed Jul 28, 2022
1 parent 7448342 commit c058904
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/logging/transformers/nodeUtilFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { TransformableInfo } from 'logform';
import { SPLAT } from 'triple-beam';
import { format } from 'util';
import * as winston from 'winston';

import { ITransformableInfo } from '../../types/logging';

/**
* Console.log style formatting using node's `util.format`. We need this so we
* can override console.{log, error, etc.} without issue.
*/
export const nodeUtilFormat = winston.format(
(info: TransformableInfo, _opts: unknown) => {
(info: ITransformableInfo, _opts: unknown) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const args = info[SPLAT as unknown as string];
if (args) {
Expand Down
21 changes: 19 additions & 2 deletions src/logging/transformers/stripAnsi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { TransformableInfo } from 'logform';
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { format } from 'winston';

import { ITransformableInfo } from '../../types/logging';

/**
* Regex pattern to match ANSI characters.
*/
Expand Down Expand Up @@ -48,7 +65,7 @@ function stripAnsiShellCodes(data: unknown): unknown {
/**
* Strip ANSI characters from `TransformableInfo.message`.
*/
export const stripAnsi = format((info: TransformableInfo, _opts: unknown) => {
export const stripAnsi = format((info: ITransformableInfo, _opts: unknown) => {
info.message = stripAnsiShellCodes(info.message) as string;
return info;
});
16 changes: 16 additions & 0 deletions src/services/test-helpers/mock/data/mockEventData.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { Codec, IEventData } from '@polkadot/types/types';

import { polkadotRegistry } from '../../../../test-helpers/registries';
Expand Down

0 comments on commit c058904

Please sign in to comment.