Merge pull request #12718 from Charge71/master

feat(logging): export redactLogLine function
This commit is contained in:
Ben Lambert
2022-07-28 14:01:25 +02:00
committed by GitHub
4 changed files with 20 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Exported `redactLogLine` function to be able to use it in custom loggers and renamed it to `redactWinstonLogLine`.
+5
View File
@@ -579,6 +579,11 @@ export type ReadUrlResponseFactoryFromStreamOptions = {
etag?: string;
};
// @public
export function redactWinstonLogLine(
info: winston.Logform.TransformableInfo,
): winston.Logform.TransformableInfo;
// @public
export function requestLoggingHandler(logger?: Logger): RequestHandler;
+6 -1
View File
@@ -15,5 +15,10 @@
*/
export * from './formats';
export { createRootLogger, getRootLogger, setRootLogger } from './rootLogger';
export {
createRootLogger,
getRootLogger,
setRootLogger,
redactWinstonLogLine,
} from './rootLogger';
export * from './voidLogger';
@@ -69,8 +69,10 @@ export function setRootLoggerRedactionList(redactionList: string[]) {
/**
* A winston formatting function that finds occurrences of filteredKeys
* and replaces them with the corresponding identifier.
*
* @public
*/
function redactLogLine(info: winston.Logform.TransformableInfo) {
export function redactWinstonLogLine(info: winston.Logform.TransformableInfo) {
// TODO(hhogg): The logger is created before the config is loaded, because the
// logger is needed in the config loader. There is a risk of a secret being
// logged out during the config loading stage.
@@ -104,7 +106,7 @@ export function createRootLogger(
{
level: env.LOG_LEVEL || 'info',
format: winston.format.combine(
winston.format(redactLogLine)(),
winston.format(redactWinstonLogLine)(),
env.NODE_ENV === 'production' ? winston.format.json() : coloredFormat,
),
defaultMeta: {