File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ const logable = fields => {
88
99 for ( const key in fields ) {
1010 Object . defineProperty ( Logable . prototype , key , {
11- get : function ( ) {
11+ get ( ) {
1212 console . log ( 'Reading key:' , key ) ;
1313 return this . values [ key ] ;
1414 } ,
15- set : function ( value ) {
15+ set ( value ) {
1616 console . log ( 'Writing key:' , key , value ) ;
1717 const def = fields [ key ] ;
1818 const valid = (
Original file line number Diff line number Diff line change 11'use strict' ;
22
33const logable = fields => class Logable {
4+
45 constructor ( data ) {
56 this . values = data ;
67 for ( const key in fields ) {
78 Object . defineProperty ( Logable . prototype , key , {
8- get : function ( ) {
9+ get ( ) {
910 console . log ( 'Reading key:' , key ) ;
1011 return this . values [ key ] ;
1112 } ,
12- set : function ( value ) {
13+ set ( value ) {
1314 console . log ( 'Writing key:' , key , value ) ;
1415 const def = fields [ key ] ;
1516 const valid = (
@@ -22,13 +23,15 @@ const logable = fields => class Logable {
2223 } ) ;
2324 }
2425 }
26+
2527 toString ( ) {
2628 let result = this . constructor . name + '\t' ;
2729 for ( const key in fields ) {
2830 result += this . values [ key ] + '\t' ;
2931 }
3032 return result ;
3133 }
34+
3235} ;
3336
3437// Usage
Original file line number Diff line number Diff line change 11'use strict' ;
22
33const logger = ( level = 'info' ) => {
4+
45 const colors = {
56 warning : '\x1b[1;33m' ,
67 error : '\x1b[0;31m' ,
78 info : '\x1b[1;37m'
89 } ;
10+
911 const color = colors [ level ] || colors . info ;
12+
1013 return s => {
1114 const date = new Date ( ) . toISOString ( ) ;
1215 console . log ( color + date + '\t' + s ) ;
1316 } ;
17+
1418} ;
1519
1620const warning = logger ( 'warning' ) ;
You can’t perform that action at this time.
0 commit comments