@@ -5,35 +5,36 @@ import { label, metric } from '@iopipe/iopipe';
55import DependencyAwareClass from '../DependencyInjection/DependencyAware.class' ;
66import DependencyInjection from '../DependencyInjection/DependencyInjection.class' ;
77
8- function replaceErrors ( key , value ) {
9- if ( value instanceof Buffer ) {
10- return value . toString ( 'base64' ) ;
11- } else if ( value instanceof Error ) {
12- const error = { } ;
13-
14- Object . getOwnPropertyNames ( value ) . forEach ( ( ( objectKey ) => {
15- error [ objectKey ] = value [ objectKey ] ;
16- } ) ) ;
17-
18- return error ;
19- }
20-
21- return value ;
22- }
23-
24-
258const logger = Winston . createLogger ( {
269 level : 'info' ,
2710 format : Winston . format . combine (
28- Winston . format . json ( { replacer : replaceErrors } ) ,
11+ Winston . format . json ( {
12+ replacer : ( key , value ) => {
13+ if ( value instanceof Buffer ) {
14+ return value . toString ( 'base64' ) ;
15+ } else if ( value instanceof Error ) {
16+ const error = { } ;
17+
18+ Object . getOwnPropertyNames ( value ) . forEach ( ( ( objectKey ) => {
19+ error [ objectKey ] = value [ objectKey ] ;
20+ } ) ) ;
21+
22+ return error ;
23+ }
24+
25+ return value ;
26+ } ,
27+ } ) ,
2928 ) ,
3029 transports : [
3130 new Winston . transports . Console ( ) ,
3231 ] ,
3332} ) ;
3433
3534// Instantiate the raven client
36- if ( typeof process . env . RAVEN_DSN !== 'undefined' ) {
35+ const ravenIsAvailable = typeof process . env . RAVEN_DSN !== 'undefined' && ( typeof process . env . RAVEN_DSN === 'string' && process . env . RAVEN_DSN !== 'undefined' ) ;
36+
37+ if ( ravenIsAvailable ) {
3738 Raven . config ( process . env . RAVEN_DSN , {
3839 sendTimeout : 5 ,
3940 environment : process . env . STAGE ,
@@ -53,7 +54,7 @@ export default class LoggerService extends DependencyAwareClass {
5354 const isOffline = context . invokedFunctionArn . indexOf ( 'offline' ) !== - 1 ;
5455
5556 // Set raven client context
56- if ( typeof process . env . RAVEN_DSN !== 'undefined' && isOffline === false ) {
57+ if ( ravenIsAvailable && isOffline === false ) {
5758 Raven . setContext ( {
5859 extra : {
5960 Event : event ,
@@ -81,7 +82,7 @@ export default class LoggerService extends DependencyAwareClass {
8182 * @param message string
8283 */
8384 error ( error , message = '' ) {
84- if ( process . env . RAVEN_DSN && error instanceof Error ) {
85+ if ( ravenIsAvailable && error instanceof Error ) {
8586 Raven . captureException ( error ) ;
8687 }
8788
0 commit comments