File tree Expand file tree Collapse file tree 6 files changed +29
-16
lines changed Expand file tree Collapse file tree 6 files changed +29
-16
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,14 @@ class Channel implements Channel {
28
28
// action may be an object.type or plain string
29
29
const actionType : string = typeof action === 'string' ? action : action . type
30
30
31
- logger ( `EXT RECEIVED: "${ actionType } "` )
31
+ if ( actionType === 'CLIENT_LOG' ) {
32
+ // logs in web client are not easily visible
33
+ // it's simpler to log to the "CodeRoad (Logs)" channel
34
+ logger ( action . payload )
35
+ return
36
+ }
37
+
38
+ logger ( actionType )
32
39
33
40
switch ( actionType ) {
34
41
case 'EDITOR_STARTUP' :
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const logger = (...messages: Log[]): void => {
9
9
// to get around it, we can log with multiple log statements
10
10
for ( const message of messages ) {
11
11
if ( typeof message === 'object' ) {
12
- logChannel . appendLine ( JSON . stringify ( message ) )
12
+ logChannel . appendLine ( message )
13
13
} else {
14
14
logChannel . appendLine ( message )
15
15
}
Original file line number Diff line number Diff line change @@ -20,8 +20,11 @@ const Routes = () => {
20
20
return < ErrorView send = { send } error = { context . error } />
21
21
}
22
22
23
- logger ( `ROUTE: ${ route } ` )
24
- logger ( `POSITION: ${ JSON . stringify ( context . position ) } ` )
23
+ logger (
24
+ `ROUTE: "${ route } ": ${ context . position ?. complete ? 'Completed' : 'On' } level ${
25
+ context . position ?. levelId || 'unknown'
26
+ } , step ${ context . position ?. stepId || 'unknown' } `,
27
+ )
25
28
26
29
return (
27
30
< Router route = { route } >
Original file line number Diff line number Diff line change 9
9
export const DEBUG : boolean = ( process . env . REACT_APP_DEBUG || '' ) . toLowerCase ( ) === 'true'
10
10
export const VERSION : string = process . env . VERSION || 'unknown'
11
11
export const NODE_ENV : string = process . env . NODE_ENV || 'development'
12
- export const LOG : boolean = ( process . env . REACT_APP_LOG || '' ) . toLowerCase ( ) === 'true'
13
12
export const TUTORIAL_LIST_URL : string = process . env . REACT_APP_TUTORIAL_LIST_URL || ''
14
13
15
14
// config variables
Original file line number Diff line number Diff line change 1
- import { LOG } from '../../environment '
1
+ import { editor } from '../state/useStateMachine '
2
2
3
3
export type Log = string | object | number | null
4
4
5
5
const logger = ( ...messages : Log [ ] ) : void => {
6
- if ( ! LOG ) {
7
- return
8
- }
6
+ // logs are difficult to view in the web client.
7
+ // for debugging purposes it's easier to collect logs in the "CodeRoad (Logs)" output channel
8
+ editor . postMessage ( {
9
+ type : 'CLIENT_LOG' ,
10
+ payload : messages ,
11
+ source : 'coderoad' , // filter events by source on editor side
12
+ } )
13
+
9
14
// Inside vscode, you console.log does not allow more than 1 param
10
15
// to get around it, we can log with multiple log statements
11
16
for ( const message of messages ) {
Original file line number Diff line number Diff line change @@ -13,21 +13,20 @@ interface Output {
13
13
14
14
declare let acquireVsCodeApi : any
15
15
16
- const editor = acquireVsCodeApi ( )
17
- const editorSend = ( action : T . Action ) => {
18
- logger ( `TO EXT: " ${ action . type } "` )
19
- return editor . postMessage ( {
16
+ export const editor = acquireVsCodeApi ( )
17
+
18
+ const editorSend = ( action : T . Action ) =>
19
+ editor . postMessage ( {
20
20
...action ,
21
21
source : 'coderoad' , // filter events by source on editor side
22
22
} )
23
- }
24
23
25
24
// router finds first state match of <Route path='' />
26
25
const useStateMachine = ( ) : Output => {
27
26
const [ state , send ] = useMachine < T . MachineContext , any > ( createMachine ( { editorSend } ) )
28
27
29
28
const sendWithLog = ( action : T . Action ) : void => {
30
- logger ( `SEND: ${ action . type } ` , action )
29
+ logger ( action )
31
30
send ( action )
32
31
}
33
32
@@ -43,7 +42,7 @@ const useStateMachine = (): Output => {
43
42
// filter out events from other extensions
44
43
return
45
44
}
46
- sendWithLog ( action )
45
+ send ( action )
47
46
}
48
47
window . addEventListener ( listener , handler )
49
48
return ( ) => {
You can’t perform that action at this time.
0 commit comments