@@ -7,7 +7,7 @@ const DATA_LIMIT = 3000;
77const Timer = require ( '../timer/timer' ) ;
88const jsonFormatter = require ( '../formatter/json' ) ;
99const consoleOutput = require ( '../output/console' ) ;
10- const allowedKeys = [ 'output' , 'formatter' ] ;
10+ const allowedKeys = [ 'output' , 'formatter' , 'transformers' ] ;
1111
1212const getContextStorage = function ( ) {
1313 const contextNamespace = continuationLocalStorage . getNamespace ( 'session' ) ;
@@ -43,21 +43,11 @@ class Logger {
4343 }
4444
4545 fromError ( action , error , data = { } ) {
46- this . error ( action , Object . assign ( {
47- error_name : error . name ,
48- error_stack : this . _shortenStackTrace ( error . stack ) ,
49- error_message : error . message ,
50- error_data : this . _shortenData ( error . data )
51- } , data ) ) ;
46+ this . error ( action , Object . assign ( this . _getErrorDetails ( error ) , data ) ) ;
5247 }
5348
5449 warnFromError ( action , error , data = { } ) {
55- this . warn ( action , Object . assign ( {
56- error_name : error . name ,
57- error_stack : this . _shortenStackTrace ( error . stack ) ,
58- error_message : error . message ,
59- error_data : this . _shortenData ( error . data )
60- } , data ) ) ;
50+ this . warn ( action , Object . assign ( this . _getErrorDetails ( error ) , data ) ) ;
6151 }
6252
6353 timer ( ) {
@@ -81,11 +71,21 @@ class Logger {
8171 ? stringifiedData . substring ( 0 , DATA_LIMIT ) + ' ...'
8272 : stringifiedData
8373 }
74+
75+ _getErrorDetails ( error ) {
76+ return {
77+ error_name : error . name ,
78+ error_stack : this . _shortenStackTrace ( error . stack ) ,
79+ error_message : error . message ,
80+ error_data : this . _shortenData ( error . data )
81+ }
82+ }
8483}
8584
8685Logger . config = {
8786 formatter : jsonFormatter ,
88- output : consoleOutput
87+ output : consoleOutput ,
88+ transformers : [ ]
8989} ;
9090
9191const logMethodFactory = function ( level ) {
@@ -94,7 +94,7 @@ const logMethodFactory = function(level) {
9494 return ;
9595 }
9696
97- const dataToLog = Object . assign (
97+ let dataToLog = Object . assign (
9898 {
9999 name : this . _namespace ,
100100 action : action ,
@@ -105,6 +105,10 @@ const logMethodFactory = function(level) {
105105 data
106106 ) ;
107107
108+ Logger . config . transformers . forEach ( ( transform ) => {
109+ dataToLog = transform ( dataToLog )
110+ } ) ;
111+
108112 Logger . config . output (
109113 Logger . config . formatter ( dataToLog )
110114 ) ;
0 commit comments