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

Commit9328da7

Browse files
committed
improve logging
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent1f8d8bd commit9328da7

File tree

15 files changed

+47
-26
lines changed

15 files changed

+47
-26
lines changed

‎src/actions/utils/openFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const openFiles = async (files: string[]) => {
2020
// ensure the panel is redrawn on the right side first
2121
vscode.commands.executeCommand(COMMANDS.OPEN_WEBVIEW)
2222
}catch(error){
23-
console.log(`Failed to open file${filePath}`,error)
23+
console.log(`Failed to open file${filePath}:${error.message}`)
2424
}
2525
}
2626
}

‎src/actions/utils/runCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const runCommands = async (commands: string[], send: (action: T.Action) => void)
1515
try{
1616
result=awaitexec(command)
1717
}catch(error){
18-
console.log(error)
18+
console.log(`Test failed:${error.message}`)
1919
send({type:'COMMAND_FAIL',payload:{process:{ ...process,status:'FAIL'}}})
2020
return
2121
}

‎src/channel/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Channel implements Channel {
4545
constactionType:string=typeofaction==='string' ?action :action.type
4646
// const onError = (error: T.ErrorMessage) => this.send({ type: 'ERROR', payload: { error }})
4747

48-
// console.log(`ACTION:${actionType}`)
48+
logger(`EXT RECEIVED: "${actionType}"`)
4949

5050
switch(actionType){
5151
case'EDITOR_STARTUP':
@@ -260,7 +260,7 @@ class Channel implements Channel {
260260
})
261261

262262
// log error to console for safe keeping
263-
console.log(`ERROR:\n${errorMarkdown}`)
263+
logger(`ERROR:\n${errorMarkdown}`)
264264

265265
if(errorMarkdown){
266266
// add a clearer error message for the user
@@ -270,6 +270,9 @@ class Channel implements Channel {
270270

271271
// action may be an object.type or plain string
272272
constactionType:string=typeofaction==='string' ?action :action.type
273+
274+
logger(`EXT TO CLIENT: "${actionType}"`)
275+
273276
switch(actionType){
274277
case'TEST_PASS':
275278
consttutorial=this.context.tutorial.get()

‎src/environment.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ require('dotenv').config({
22
path:'./web-app/.env',
33
})
44

5-
import*asvscodefrom'vscode'
65
import{getWorkspaceRoot}from'./services/workspace'
76

87
interfaceEnvironment{
@@ -17,7 +16,7 @@ interface Environment {
1716
constenvironment:Environment={
1817
VERSION:process.env.VERSION||'unknown',
1918
NODE_ENV:process.env.NODE_ENV||'production',
20-
LOG:(process.env.LOG||'').toLowerCase()==='true',
19+
LOG:(process.env.REACT_APP_LOG||'').toLowerCase()==='true'&&process.env.NODE_ENV!=='production',
2120
API_URL:process.env.REACT_APP_GQL_URI||'',
2221
SENTRY_DSN:process.env.SENTRY_DSN||null,
2322
WORKSPACE_ROOT:getWorkspaceRoot(),

‎web-app/.storybook/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import '../src/styles/index.css'
55
//@ts-ignore
66
global.acquireVsCodeApi=()=>({
77
postMessage(event:string){
8-
console.log('postMessage',event)
8+
console.log('ERROR: VSCode did not load properly in CodeRoad extension',event)
99
},
1010
})
1111

‎web-app/src/components/Error/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const ErrorMarkdown = ({ error, send }: Props) => {
4040
React.useEffect(()=>{
4141
if(error){
4242
// log error
43-
console.log(error)
43+
console.log(`ERROR in markdown:${error.message}`)
4444
}
4545
},[error])
4646

‎web-app/src/components/ErrorBoundary/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import*asReactfrom'react'
22
importonErrorfrom'../../services/sentry/onError'
3+
importloggerfrom'../../services/logger'
34

45
classErrorBoundaryextendsReact.Component{
56
publicstate={errorMessage:null}
@@ -9,8 +10,8 @@ class ErrorBoundary extends React.Component {
910
// Display fallback UI
1011
this.setState({errorMessage:error.message})
1112
// You can also log the error to an error reporting service
12-
console.error(JSON.stringify(error))
13-
console.log(JSON.stringify(info))
13+
logger('ERROR in component:',JSON.stringify(error))
14+
logger('ERROR info:',JSON.stringify(info))
1415
}
1516

1617
publicrender(){

‎web-app/src/components/Markdown/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const Markdown = (props: Props) => {
6767
try{
6868
html=md.render(props.children)
6969
}catch(error){
70-
constmessage=`failed to parse markdown for${props.children}`
70+
constmessage=`Failed to parse markdown for${props.children}`
7171
onError(newError(message))
7272
console.log(message)
7373
html=`<div style='background-color: #FFB81A; padding: 0.5rem;'>

‎web-app/src/components/Router/index.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createMachine } from '../../services/state/machine'
44
import{useMachine}from'../../services/xstate-react'
55
importRoutefrom'./Route'
66
importonErrorfrom'../../services/sentry/onError'
7-
import{LOG_STATE}from'../../environment'
7+
importloggerfrom'../../services/logger'
88

99
interfaceOutput{
1010
context:T.MachineContext
@@ -16,27 +16,30 @@ interface Output {
1616
declareletacquireVsCodeApi:any
1717

1818
consteditor=acquireVsCodeApi()
19+
consteditorSend=(action:T.Action)=>{
20+
logger(`CLIENT TO EXT: "${action.type}"`)
21+
returneditor.postMessage(action)
22+
}
1923

2024
// router finds first state match of <Route path='' />
2125
constuseRouter=():Output=>{
22-
const[state,send]=useMachine<T.MachineContext,any>(createMachine({editorSend:editor.postMessage}))
26+
const[state,send]=useMachine<T.MachineContext,any>(createMachine({ editorSend}))
2327

24-
if(LOG_STATE){
25-
console.log(JSON.stringify(state.value))
26-
}
28+
logger(`STATE:${JSON.stringify(state.value)}`)
2729

2830
// event bus listener
2931
React.useEffect(()=>{
3032
constlistener='message'
3133
// propograte channel event to state machine
32-
consthandler=(action:any)=>{
34+
consthandler=(event:any)=>{
3335
// NOTE: must call event.data, cannot destructure. VSCode acts odd
34-
constevent=action.data
36+
constaction=event.data
3537
// ignore browser events from plugins
36-
if(event.source){
38+
if(action.source){
3739
return
3840
}
39-
send(event)
41+
logger(`CLIENT RECEIVED: "${action.type}"`)
42+
send(action)
4043
}
4144
window.addEventListener(listener,handler)
4245
return()=>{

‎web-app/src/containers/SelectTutorial/LoadTutorialSummary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const LoadTutorialSummary = (props: Props) => {
1414
return<Loadingtext="Loading tutorial summary..."/>
1515
}
1616
if(error){
17-
console.log(error)
17+
console.log(`Failed to load tutorial summary:${error}`)
1818
return<div>Error loading summary</div>
1919
}
2020
if(!data){

‎web-app/src/containers/SelectTutorial/forms/TutorialUrl.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import*asReactfrom'react'
22
import{Button,Form,Input}from'@alifd/next'
3+
importloggerfrom'../../../services/logger'
34

45
constFormItem=Form.Item
56

@@ -12,7 +13,7 @@ const TutorialUrl = (props: Props) => {
1213
const[url,setUrl]=React.useState(props.defaultUrl)
1314
constonSubmit=(e:any)=>{
1415
e.preventDefault()
15-
console.log('tutorial url',url)
16+
logger(`Tutorial url:${url}`)
1617
props.onTutorialLoad(url)
1718
}
1819

‎web-app/src/environment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ for (const required of requiredKeys) {
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_STATE:boolean=(process.env.REACT_APP_LOG_STATE||'').toLowerCase()==='true'
12+
exportconstLOG:boolean=
13+
(process.env.REACT_APP_LOG||'').toLowerCase()==='true'&&process.env.NODE_ENV!=='production'
1314
exportconstTUTORIAL_LIST_URL:string=process.env.REACT_APP_TUTORIAL_LIST_URL||''
1415
exportconstSENTRY_DSN:string|null=process.env.REACT_APP_SENTRY_DSN||null

‎web-app/src/mock/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if (!global.acquireVsCodeApi) {
33
//@ts-ignore
44
global.acquireVsCodeApi=()=>({
55
postMessage(event:string){
6-
console.log('postMessage',event)
6+
console.log('VSCode did not load properly for CodeRoad extension',event)
77
},
88
})
99
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import{LOG}from'../../environment'
2+
3+
constlogger=(...messages:string[])=>{
4+
if(!LOG){
5+
return
6+
}
7+
// Inside vscode, you console.log does not allow more than 1 param
8+
// to get around it, we can log with multiple log statements
9+
for(constmessageofmessages){
10+
console.log(message)
11+
}
12+
}
13+
14+
exportdefaultlogger

‎web-app/src/services/sentry/init.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ try {
99
})
1010
}
1111
}catch(error){
12-
console.log('Error in Sentry init')
13-
console.log(error)
12+
console.log(`Error in Sentry init:${error.message}`)
1413
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp