@@ -7,7 +7,7 @@ const DATA_LIMIT = 3000;
7
7
const Timer = require ( '../timer/timer' ) ;
8
8
const jsonFormatter = require ( '../formatter/json' ) ;
9
9
const consoleOutput = require ( '../output/console' ) ;
10
- const allowedKeys = [ 'output' , 'formatter' ] ;
10
+ const allowedKeys = [ 'output' , 'formatter' , 'transformers' ] ;
11
11
12
12
const getContextStorage = function ( ) {
13
13
const contextNamespace = continuationLocalStorage . getNamespace ( 'session' ) ;
@@ -43,21 +43,11 @@ class Logger {
43
43
}
44
44
45
45
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 ) ) ;
52
47
}
53
48
54
49
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 ) ) ;
61
51
}
62
52
63
53
timer ( ) {
@@ -81,11 +71,21 @@ class Logger {
81
71
? stringifiedData . substring ( 0 , DATA_LIMIT ) + ' ...'
82
72
: stringifiedData
83
73
}
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
+ }
84
83
}
85
84
86
85
Logger . config = {
87
86
formatter : jsonFormatter ,
88
- output : consoleOutput
87
+ output : consoleOutput ,
88
+ transformers : [ ]
89
89
} ;
90
90
91
91
const logMethodFactory = function ( level ) {
@@ -94,7 +94,7 @@ const logMethodFactory = function(level) {
94
94
return ;
95
95
}
96
96
97
- const dataToLog = Object . assign (
97
+ let dataToLog = Object . assign (
98
98
{
99
99
name : this . _namespace ,
100
100
action : action ,
@@ -105,6 +105,10 @@ const logMethodFactory = function(level) {
105
105
data
106
106
) ;
107
107
108
+ Logger . config . transformers . forEach ( ( transform ) => {
109
+ dataToLog = transform ( dataToLog )
110
+ } ) ;
111
+
108
112
Logger . config . output (
109
113
Logger . config . formatter ( dataToLog )
110
114
) ;
0 commit comments