Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1d4e3b

Browse files
committed
send logs from client to ext channel
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent4e1e1a5 commitb1d4e3b

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

‎src/channel.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ class Channel implements Channel {
2828
// action may be an object.type or plain string
2929
constactionType:string=typeofaction==='string' ?action :action.type
3030

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)
3239

3340
switch(actionType){
3441
case'EDITOR_STARTUP':

‎src/services/logger/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const logger = (...messages: Log[]): void => {
99
// to get around it, we can log with multiple log statements
1010
for(constmessageofmessages){
1111
if(typeofmessage==='object'){
12-
logChannel.appendLine(JSON.stringify(message))
12+
logChannel.appendLine(message)
1313
}else{
1414
logChannel.appendLine(message)
1515
}

‎web-app/src/Routes.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ const Routes = () => {
2020
return<ErrorViewsend={send}error={context.error}/>
2121
}
2222

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+
)
2528

2629
return(
2730
<Routerroute={route}>

‎web-app/src/environment.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
exportconstDEBUG:boolean=(process.env.REACT_APP_DEBUG||'').toLowerCase()==='true'
1010
exportconstVERSION:string=process.env.VERSION||'unknown'
1111
exportconstNODE_ENV:string=process.env.NODE_ENV||'development'
12-
exportconstLOG:boolean=(process.env.REACT_APP_LOG||'').toLowerCase()==='true'
1312
exportconstTUTORIAL_LIST_URL:string=process.env.REACT_APP_TUTORIAL_LIST_URL||''
1413

1514
// config variables

‎web-app/src/services/logger/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import{LOG}from'../../environment'
1+
import{editor}from'../state/useStateMachine'
22

33
exporttypeLog=string|object|number|null
44

55
constlogger=(...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+
914
// Inside vscode, you console.log does not allow more than 1 param
1015
// to get around it, we can log with multiple log statements
1116
for(constmessageofmessages){

‎web-app/src/services/state/useStateMachine.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@ interface Output {
1313

1414
declareletacquireVsCodeApi:any
1515

16-
consteditor=acquireVsCodeApi()
17-
consteditorSend=(action:T.Action)=>{
18-
logger(`TO EXT: "${action.type}"`)
19-
returneditor.postMessage({
16+
exportconsteditor=acquireVsCodeApi()
17+
18+
consteditorSend=(action:T.Action)=>
19+
editor.postMessage({
2020
...action,
2121
source:'coderoad',// filter events by source on editor side
2222
})
23-
}
2423

2524
// router finds first state match of <Route path='' />
2625
constuseStateMachine=():Output=>{
2726
const[state,send]=useMachine<T.MachineContext,any>(createMachine({ editorSend}))
2827

2928
constsendWithLog=(action:T.Action):void=>{
30-
logger(`SEND:${action.type}`,action)
29+
logger(action)
3130
send(action)
3231
}
3332

@@ -43,7 +42,7 @@ const useStateMachine = (): Output => {
4342
// filter out events from other extensions
4443
return
4544
}
46-
sendWithLog(action)
45+
send(action)
4746
}
4847
window.addEventListener(listener,handler)
4948
return()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp