mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 17:42:57 +00:00
fix: removing transformations in production
This commit is contained in:
@@ -106,9 +106,7 @@ export class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let transformedOutput = output;
|
let transformedOutput = output;
|
||||||
for (const transformation of Logger.transformations.filter(transform =>
|
for (const transformation of Logger.transformations) {
|
||||||
!isProductiveEnvironment() ? true : transform.useInProduction === isProductiveEnvironment(),
|
|
||||||
)) {
|
|
||||||
transformedOutput = transformation.transform(logLevel, transformedOutput);
|
transformedOutput = transformation.transform(logLevel, transformedOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +290,10 @@ export class Logger {
|
|||||||
* @param transformations List of transformations
|
* @param transformations List of transformations
|
||||||
*/
|
*/
|
||||||
public static setTransformations(transformations: Transformation[]) {
|
public static setTransformations(transformations: Transformation[]) {
|
||||||
Logger.transformations = transformations;
|
const transforms = transformations.filter(transform =>
|
||||||
|
isProductiveEnvironment() ? transform.useInProduction === true : true,
|
||||||
|
);
|
||||||
|
Logger.transformations = transforms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -239,20 +239,27 @@ export class LoggerSpec {
|
|||||||
|
|
||||||
@test
|
@test
|
||||||
'is compatible with log aggregation in productive environment'() {
|
'is compatible with log aggregation in productive environment'() {
|
||||||
const nodeEnv = process.env.NODE_ENV;
|
|
||||||
process.env.NODE_ENV = 'production';
|
|
||||||
process.env.ALLOW_NO_TRANSPORT = 'true';
|
|
||||||
|
|
||||||
Logger.setTransformations([new AddLogLevel(), new Colorize()]);
|
Logger.setTransformations([new AddLogLevel(), new Colorize()]);
|
||||||
|
|
||||||
const spy = LoggerSpec.sandbox.on(console, 'log', () => {
|
let spy = LoggerSpec.sandbox.on(console, 'log', () => {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
|
|
||||||
Logger.log('Foo\nbar');
|
Logger.log('Foo\nbar');
|
||||||
|
|
||||||
expect(spy).to.have.been.called.once;
|
expect(spy).to.have.been.called.once;
|
||||||
expect(spy.__spy.calls[0][0]).to.equal('[LOG] Foo bar');
|
expect(spy.__spy.calls[0][0]).to.equal('\u001B[37m[LOG] Foo\u001B[39m\n\u001B[37mbar\u001B[39m');
|
||||||
|
|
||||||
|
const nodeEnv = process.env.NODE_ENV;
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
process.env.ALLOW_NO_TRANSPORT = 'true';
|
||||||
|
|
||||||
|
Logger.setTransformations([new AddLogLevel(), new Colorize()]);
|
||||||
|
|
||||||
|
Logger.log('Foo\nbar');
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called.twice;
|
||||||
|
expect(spy.__spy.calls[1][0]).to.equal('[LOG] Foo bar');
|
||||||
|
|
||||||
process.env.NODE_ENV = nodeEnv;
|
process.env.NODE_ENV = nodeEnv;
|
||||||
delete process.env.ALLOW_NO_TRANSPORT;
|
delete process.env.ALLOW_NO_TRANSPORT;
|
||||||
|
|||||||
Reference in New Issue
Block a user