backend-plugin-api: inlined LogMeta type

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-02-06 16:36:29 +01:00
parent 606bb891c1
commit 71a5ec0f06
8 changed files with 54 additions and 44 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-plugin-api': minor
---
**BREAKING**: Inlined `LogMeta` type.
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/backend-test-utils': patch
'@backstage/backend-app-api': patch
---
Updated usages of `LogMeta`.
+6 -7
View File
@@ -21,7 +21,6 @@ import { IdentityService } from '@backstage/backend-plugin-api';
import { LifecycleService } from '@backstage/backend-plugin-api';
import { LoadConfigOptionsRemote } from '@backstage/config-loader';
import { LoggerService } from '@backstage/backend-plugin-api';
import { LogMeta } from '@backstage/backend-plugin-api';
import { PermissionsService } from '@backstage/backend-plugin-api';
import { PluginCacheManager } from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
@@ -263,21 +262,21 @@ export class WinstonLogger implements RootLoggerService {
// (undocumented)
addRedactions(redactions: Iterable<string>): void;
// (undocumented)
child(meta: LogMeta): LoggerService;
child(meta: Record<string, unknown>): LoggerService;
static colorFormat(): Format;
static create(options: WinstonLoggerOptions): WinstonLogger;
// (undocumented)
debug(message: string, meta?: LogMeta): void;
debug(message: string, meta?: Record<string, unknown>): void;
// (undocumented)
error(message: string, meta?: LogMeta): void;
error(message: string, meta?: Record<string, unknown>): void;
// (undocumented)
info(message: string, meta?: LogMeta): void;
info(message: string, meta?: Record<string, unknown>): void;
static redacter(): {
format: Format;
add: (redactions: Iterable<string>) => void;
};
// (undocumented)
warn(message: string, meta?: LogMeta): void;
warn(message: string, meta?: Record<string, unknown>): void;
}
// @public (undocumented)
@@ -287,7 +286,7 @@ export interface WinstonLoggerOptions {
// (undocumented)
level: string;
// (undocumented)
meta?: LogMeta;
meta?: Record<string, unknown>;
// (undocumented)
transports: transport[];
}
@@ -16,7 +16,6 @@
import {
LoggerService,
LogMeta,
RootLoggerService,
} from '@backstage/backend-plugin-api';
import { Format, TransformableInfo } from 'logform';
@@ -33,7 +32,7 @@ import { escapeRegExp } from '../lib/escapeRegExp';
* @public
*/
export interface WinstonLoggerOptions {
meta?: LogMeta;
meta?: Record<string, unknown>;
level: string;
format: Format;
transports: Transport[];
@@ -150,23 +149,23 @@ export class WinstonLogger implements RootLoggerService {
this.#addRedactions = addRedactions;
}
error(message: string, meta?: LogMeta): void {
error(message: string, meta?: Record<string, unknown>): void {
this.#winston.error(message, meta);
}
warn(message: string, meta?: LogMeta): void {
warn(message: string, meta?: Record<string, unknown>): void {
this.#winston.warn(message, meta);
}
info(message: string, meta?: LogMeta): void {
info(message: string, meta?: Record<string, unknown>): void {
this.#winston.info(message, meta);
}
debug(message: string, meta?: LogMeta): void {
debug(message: string, meta?: Record<string, unknown>): void {
this.#winston.debug(message, meta);
}
child(meta: LogMeta): LoggerService {
child(meta: Record<string, unknown>): LoggerService {
return new WinstonLogger(this.#winston.child(meta));
}
+5 -10
View File
@@ -311,22 +311,17 @@ export interface LifecycleServiceShutdownOptions {
// @public
export interface LoggerService {
// (undocumented)
child(meta: LogMeta): LoggerService;
child(meta: Record<string, unknown>): LoggerService;
// (undocumented)
debug(message: string, meta?: Error | LogMeta): void;
debug(message: string, meta?: Error | Record<string, unknown>): void;
// (undocumented)
error(message: string, meta?: Error | LogMeta): void;
error(message: string, meta?: Error | Record<string, unknown>): void;
// (undocumented)
info(message: string, meta?: Error | LogMeta): void;
info(message: string, meta?: Error | Record<string, unknown>): void;
// (undocumented)
warn(message: string, meta?: Error | LogMeta): void;
warn(message: string, meta?: Error | Record<string, unknown>): void;
}
// @public (undocumented)
export type LogMeta = {
[name: string]: unknown;
};
// @public (undocumented)
export interface PermissionsService extends PermissionEvaluator {}
@@ -14,21 +14,16 @@
* limitations under the License.
*/
/**
* @public
*/
export type LogMeta = { [name: string]: unknown };
/**
* A service that provides a logging facility.
*
* @public
*/
export interface LoggerService {
error(message: string, meta?: Error | LogMeta): void;
warn(message: string, meta?: Error | LogMeta): void;
info(message: string, meta?: Error | LogMeta): void;
debug(message: string, meta?: Error | LogMeta): void;
error(message: string, meta?: Error | Record<string, unknown>): void;
warn(message: string, meta?: Error | Record<string, unknown>): void;
info(message: string, meta?: Error | Record<string, unknown>): void;
debug(message: string, meta?: Error | Record<string, unknown>): void;
child(meta: LogMeta): LoggerService;
child(meta: Record<string, unknown>): LoggerService;
}
@@ -30,7 +30,7 @@ export type {
LifecycleServiceShutdownHook,
LifecycleServiceShutdownOptions,
} from './LifecycleService';
export type { LoggerService, LogMeta } from './LoggerService';
export type { LoggerService } from './LoggerService';
export type { PermissionsService } from './PermissionsService';
export type { PluginMetadataService } from './PluginMetadataService';
export type { RootHttpRouterService } from './RootHttpRouterService';
@@ -16,38 +16,49 @@
import {
LoggerService,
LogMeta,
RootLoggerService,
} from '@backstage/backend-plugin-api';
import type { mockServices } from './mockServices';
export class MockRootLoggerService implements RootLoggerService {
#levels: Exclude<mockServices.rootLogger.Options['levels'], boolean>;
#meta: LogMeta;
#meta: Record<string, unknown>;
error(message: string, meta?: LogMeta | Error | undefined): void {
error(
message: string,
meta?: Record<string, unknown> | Error | undefined,
): void {
this.#log('error', message, meta);
}
warn(message: string, meta?: LogMeta | Error | undefined): void {
warn(
message: string,
meta?: Record<string, unknown> | Error | undefined,
): void {
this.#log('warn', message, meta);
}
info(message: string, meta?: LogMeta | Error | undefined): void {
info(
message: string,
meta?: Record<string, unknown> | Error | undefined,
): void {
this.#log('info', message, meta);
}
debug(message: string, meta?: LogMeta | Error | undefined): void {
debug(
message: string,
meta?: Record<string, unknown> | Error | undefined,
): void {
this.#log('debug', message, meta);
}
child(meta: LogMeta): LoggerService {
child(meta: Record<string, unknown>): LoggerService {
return new MockRootLoggerService(this.#levels, { ...this.#meta, ...meta });
}
constructor(
levels: mockServices.rootLogger.Options['levels'],
meta: LogMeta,
meta: Record<string, unknown>,
) {
if (typeof levels === 'boolean') {
this.#levels = {
@@ -65,7 +76,7 @@ export class MockRootLoggerService implements RootLoggerService {
#log(
level: 'error' | 'warn' | 'info' | 'debug',
message: string,
meta?: LogMeta | Error | undefined,
meta?: Record<string, unknown> | Error | undefined,
) {
if (this.#levels[level]) {
const labels = Object.entries(this.#meta)