backend-plugin-api: moved loggerToWinstonLogger to backend-common

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-03 15:43:07 +01:00
parent 19843ff915
commit 8e06f3cf00
32 changed files with 68 additions and 53 deletions
@@ -7,14 +7,12 @@
import { Config } from '@backstage/config';
import { Handler } from 'express';
import { Logger } from 'winston';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
import { PluginCacheManager } from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { PluginTaskScheduler } from '@backstage/backend-tasks';
import { Readable } from 'stream';
import { TokenManager } from '@backstage/backend-common';
import { TransportStreamOptions } from 'winston-transport';
// @public (undocumented)
export interface BackendFeature {
@@ -201,12 +199,6 @@ export interface LoggerService {
warn(message: string, meta?: Error | LogMeta): void;
}
// @public (undocumented)
export function loggerToWinstonLogger(
logger: LoggerService,
opts?: TransportStreamOptions,
): Logger;
// @public (undocumented)
export type LogMeta = {
[name: string]: unknown;
+1 -3
View File
@@ -38,9 +38,7 @@
"@backstage/config": "workspace:^",
"@backstage/plugin-permission-common": "workspace:^",
"@types/express": "^4.17.6",
"express": "^4.17.1",
"winston": "^3.2.1",
"winston-transport": "^4.5.0"
"express": "^4.17.1"
},
"devDependencies": {
"@backstage/cli": "workspace:^"
@@ -1,17 +0,0 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { loggerToWinstonLogger } from './loggerToWinstonLogger';
@@ -1,63 +0,0 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LoggerService } from '../definitions';
import { Logger as WinstonLogger, createLogger } from 'winston';
import Transport, { TransportStreamOptions } from 'winston-transport';
class BackstageLoggerTransport extends Transport {
constructor(
private readonly backstageLogger: LoggerService,
opts?: TransportStreamOptions,
) {
super(opts);
}
log(info: unknown, callback: VoidFunction) {
if (typeof info !== 'object' || info === null) {
callback();
return;
}
const { level, message, ...meta } = info as { [name: string]: unknown };
switch (level) {
case 'error':
this.backstageLogger.error(String(message), meta);
break;
case 'warn':
this.backstageLogger.warn(String(message), meta);
break;
case 'info':
this.backstageLogger.info(String(message), meta);
break;
case 'debug':
this.backstageLogger.debug(String(message), meta);
break;
default:
this.backstageLogger.info(String(message), meta);
}
callback();
}
}
/** @public */
export function loggerToWinstonLogger(
logger: LoggerService,
opts?: TransportStreamOptions,
): WinstonLogger {
return createLogger({
transports: [new BackstageLoggerTransport(logger, opts)],
});
}
@@ -15,5 +15,4 @@
*/
export * from './definitions';
export * from './helpers';
export * from './system';