@@ -6,13 +6,14 @@ export default function createLogger ({
6
6
collapsed = true ,
7
7
filter = ( mutation , stateBefore , stateAfter ) => true ,
8
8
transformer = state => state ,
9
- mutationTransformer = mut => mut
9
+ mutationTransformer = mut => mut ,
10
+ logger = console
10
11
} = { } ) {
11
12
return store => {
12
13
let prevState = deepCopy ( store . state )
13
14
14
15
store . subscribe ( ( mutation , state ) => {
15
- if ( typeof console === 'undefined' ) {
16
+ if ( typeof logger === 'undefined' ) {
16
17
return
17
18
}
18
19
const nextState = deepCopy ( state )
@@ -23,24 +24,24 @@ export default function createLogger ({
23
24
const formattedMutation = mutationTransformer ( mutation )
24
25
const message = `mutation ${ mutation . type } ${ formattedTime } `
25
26
const startMessage = collapsed
26
- ? console . groupCollapsed
27
- : console . group
27
+ ? logger . groupCollapsed
28
+ : logger . group
28
29
29
30
// render
30
31
try {
31
- startMessage . call ( console , message )
32
+ startMessage . call ( logger , message )
32
33
} catch ( e ) {
33
34
console . log ( message )
34
35
}
35
36
36
- console . log ( '%c prev state' , 'color: #9E9E9E; font-weight: bold' , transformer ( prevState ) )
37
- console . log ( '%c mutation' , 'color: #03A9F4; font-weight: bold' , formattedMutation )
38
- console . log ( '%c next state' , 'color: #4CAF50; font-weight: bold' , transformer ( nextState ) )
37
+ logger . log ( '%c prev state' , 'color: #9E9E9E; font-weight: bold' , transformer ( prevState ) )
38
+ logger . log ( '%c mutation' , 'color: #03A9F4; font-weight: bold' , formattedMutation )
39
+ logger . log ( '%c next state' , 'color: #4CAF50; font-weight: bold' , transformer ( nextState ) )
39
40
40
41
try {
41
- console . groupEnd ( )
42
+ logger . groupEnd ( )
42
43
} catch ( e ) {
43
- console . log ( '—— log end ——' )
44
+ logger . log ( '—— log end ——' )
44
45
}
45
46
}
46
47
0 commit comments