@@ -4,41 +4,51 @@ const config = require('../config');
44const continuationLocalStorage = require ( 'cls-hooked' ) ;
55const _ = require ( 'lodash' ) ;
66const STACK_TRACE_LIMIT = 4000 ;
7+ const Timer = require ( '../timer/timer' ) ;
78
89const logMethodFactory = function ( level ) {
910 return function ( action , data ) {
10- if ( ! this . enabled ) {
11+ if ( ! this . _enabled ) {
1112 return ;
1213 }
1314
14- const namespace = continuationLocalStorage . getNamespace ( 'session' ) ;
15- const storage = ( namespace && namespace . active ) ? _ . omit ( namespace . active , 'id' , '_ns_name' ) : { } ;
15+ const contextNamespace = continuationLocalStorage . getNamespace ( 'session' ) ;
16+ const contextStorage = ( contextNamespace && contextNamespace . active ) ?
17+ _ . omit ( contextNamespace . active , 'id' , '_ns_name' ) : { } ;
1618
1719 console . log ( JSON . stringify ( Object . assign (
1820 {
19- name : this . namespace ,
21+ name : this . _namespace ,
2022 action : action ,
2123 level : config . levels [ level ] . number ,
2224 time : new Date ( ) . toISOString ( )
2325 } ,
24- storage ,
26+ contextStorage ,
2527 data
2628 ) ) ) ;
2729 }
2830} ;
2931
3032class Logger {
3133 constructor ( namespace , enabled ) {
32- this . namespace = namespace ;
33- this . enabled = enabled ;
34+ this . _namespace = namespace ;
35+ this . _enabled = enabled ;
3436 }
3537
36- fromError ( action , error , options = { } ) {
38+ isEnabled ( ) {
39+ return this . _enabled ;
40+ }
41+
42+ fromError ( action , error , data = { } ) {
3743 this . error ( action , Object . assign ( {
3844 error_name : error . name ,
3945 error_stack : this . _shortenStackTrace ( error ) ,
4046 error_message : error . message
41- } , options ) ) ;
47+ } , data ) ) ;
48+ }
49+
50+ timer ( ) {
51+ return new Timer ( this ) ;
4252 }
4353
4454 _shortenStackTrace ( error ) {
0 commit comments