backend-plugin-api: update logger interface with more methods and meta

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Johan Haals <johan.haals@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-12-14 17:20:20 +01:00
parent a219b735dc
commit cb1c2781c0
5 changed files with 39 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-app-api': patch
---
Updated logger implementations to match interface changes.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-plugin-api': patch
---
Updated `LoggerService` interface with more log methods and meta.
@@ -20,6 +20,7 @@ import {
LoggerService,
coreServices,
} from '@backstage/backend-plugin-api';
import { LogMeta } from '@backstage/backend-plugin-api';
import { Logger as WinstonLogger } from 'winston';
class BackstageLogger implements LoggerService {
@@ -29,12 +30,24 @@ class BackstageLogger implements LoggerService {
private constructor(private readonly winston: WinstonLogger) {}
info(message: string, ...meta: any[]): void {
this.winston.info(message, ...meta);
error(message: string, meta?: LogMeta): void {
this.winston.error(message, meta);
}
child(fields: { [name: string]: string }): LoggerService {
return new BackstageLogger(this.winston.child(fields));
warn(message: string, meta?: LogMeta): void {
this.winston.warn(message, meta);
}
info(message: string, meta?: LogMeta): void {
this.winston.info(message, meta);
}
debug(message: string, meta?: LogMeta): void {
this.winston.debug(message, meta);
}
child(meta: LogMeta): LoggerService {
return new BackstageLogger(this.winston.child(meta));
}
}
@@ -26,7 +26,7 @@ export type {
LifecycleService,
LifecycleServiceShutdownHook,
} from './lifecycleServiceRef';
export type { LoggerService } from './loggerServiceRef';
export type { LoggerService, LogMeta } from './loggerServiceRef';
export type { PermissionsService } from './permissionsServiceRef';
export type { PluginMetadataService } from './pluginMetadataServiceRef';
export type { RootLoggerService } from './rootLoggerServiceRef';
@@ -16,12 +16,21 @@
import { createServiceRef } from '../system/types';
/**
* @public
*/
export type LogMeta = Error | { [name: string]: any };
/**
* @public
*/
export interface LoggerService {
info(message: string): void;
child(fields: { [name: string]: string }): LoggerService;
error(message: string, meta?: LogMeta): void;
warn(message: string, meta?: LogMeta): void;
info(message: string, meta?: LogMeta): void;
debug(message: string, meta?: LogMeta): void;
child(meta: LogMeta): LoggerService;
}
/**