File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -69,11 +69,14 @@ const prettificationAvailable = (() => {
69
69
/**
70
70
* Whether log prettification is allowed. We never allow log
71
71
* prettification if the `NODE_ENV` environment variable is
72
- * set to "production".
72
+ * set to "production". We also disallow prettification if the
73
+ * cloud provider is AWS, pino-pretty does not work well with
74
+ * CloudWatch logs
73
75
*
74
76
* @type {boolean }
75
77
*/
76
- const prettificationAllowed = appInfo . environment !== 'production' ;
78
+ const prettificationAllowed =
79
+ appInfo . environment !== 'production' && appInfo . cloudProvider !== 'aws' ;
77
80
78
81
/**
79
82
* Class representing a logger.
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ jest.mock('pino-pretty', () => {
28
28
} ) ;
29
29
30
30
jest . mock ( '@dotcom-reliability-kit/app-info' , ( ) => ( {
31
+ cloudProvider : null ,
31
32
environment : 'production'
32
33
} ) ) ;
33
34
const appInfo = require ( '@dotcom-reliability-kit/app-info' ) ;
@@ -1085,6 +1086,32 @@ describe('@dotcom-reliability-kit/logger/lib/logger', () => {
1085
1086
} ) ;
1086
1087
} ) ;
1087
1088
1089
+ describe ( 'when pino-pretty is installed and AWS is detected as a cloud provider' , ( ) => {
1090
+ beforeEach ( ( ) => {
1091
+ jest . mock ( 'pino-pretty' , ( ) => 'mock pino pretty' ) ;
1092
+ appInfo . cloudProvider = 'aws' ;
1093
+
1094
+ // We have to reset all modules because the checks for pino-pretty are done
1095
+ // on module load for performance reasons. This resets the cache and reloads
1096
+ // everything with a new environment.
1097
+ jest . isolateModules ( ( ) => {
1098
+ Logger = require ( '../../../lib/logger' ) ;
1099
+ } ) ;
1100
+
1101
+ pino . mockClear ( ) ;
1102
+ logger = new Logger ( ) ;
1103
+ } ) ;
1104
+
1105
+ afterEach ( ( ) => {
1106
+ jest . unmock ( 'pino-pretty' ) ;
1107
+ } ) ;
1108
+
1109
+ it ( 'does not configure the created Pino logger with prettification' , ( ) => {
1110
+ const pinoOptions = pino . mock . calls [ 0 ] [ 0 ] ;
1111
+ expect ( pinoOptions . transport ) . toBeUndefined ( ) ;
1112
+ } ) ;
1113
+ } ) ;
1114
+
1088
1115
describe ( 'when pino-pretty is not installed and the environment is "development"' , ( ) => {
1089
1116
beforeEach ( ( ) => {
1090
1117
appInfo . environment = 'development' ;
You can’t perform that action at this time.
0 commit comments