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

fix(logging): replace TransformableInfo with ITransformableInfo type #994

Merged
merged 2 commits into from
Jul 28, 2022
Merged
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
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