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

Commit4d7c100

Browse files
authored
Merge pull requestcoderoad#254 from coderoad/improve-logging
Improve logging
2 parents1f8d8bd +b1298cc commit4d7c100

File tree

23 files changed

+85
-61
lines changed

23 files changed

+85
-61
lines changed

‎src/actions/utils/loadWatchers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*aschokidarfrom'chokidar'
22
import*asvscodefrom'vscode'
33
import{COMMANDS}from'../../editor/commands'
4-
importenvironmentfrom'../../environment'
4+
import{WORKSPACE_ROOT}from'../../environment'
55

66
// NOTE: vscode createFileWatcher doesn't seem to detect changes outside of vscode
77
// such as `npm install` of a package. Went with chokidar instead
@@ -26,7 +26,7 @@ const loadWatchers = (watchers: string[]) => {
2626
// see how glob patterns are used in VSCode (not like a regex)
2727
// https://code.visualstudio.com/api/references/vscode-api#GlobPattern
2828
constfsWatcher:chokidar.FSWatcher=chokidar.watch(watcher,{
29-
cwd:environment.WORKSPACE_ROOT,
29+
cwd:WORKSPACE_ROOT,
3030
interval:1000,
3131
})
3232

‎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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'
1414
import{readFile}from'fs'
1515
import{join}from'path'
1616
import{promisify}from'util'
17-
importenvironmentfrom'../environment'
17+
import{WORKSPACE_ROOT}from'../environment'
1818

1919
constreadFileAsync=promisify(readFile)
2020

@@ -45,12 +45,12 @@ 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':
5252
// check if a workspace is open, otherwise nothing works
53-
constnoActiveWorksapce=!environment.WORKSPACE_ROOT.length
53+
constnoActiveWorksapce=!WORKSPACE_ROOT.length
5454
if(noActiveWorksapce){
5555
consterror:E.ErrorMessage={
5656
type:'NoWorkspaceFound',
@@ -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: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@ require('dotenv').config({
22
path:'./web-app/.env',
33
})
44

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

8-
interfaceEnvironment{
9-
VERSION:string
10-
NODE_ENV:string
11-
LOG:boolean
12-
API_URL:string
13-
SENTRY_DSN:string|null
14-
WORKSPACE_ROOT:string
15-
}
7+
// CodeRoad version
8+
exportconstVERSION:string=process.env.npm_package_version||'unknown'
169

17-
constenvironment:Environment={
18-
VERSION:process.env.VERSION||'unknown',
19-
NODE_ENV:process.env.NODE_ENV||'production',
20-
LOG:(process.env.LOG||'').toLowerCase()==='true',
21-
API_URL:process.env.REACT_APP_GQL_URI||'',
22-
SENTRY_DSN:process.env.SENTRY_DSN||null,
23-
WORKSPACE_ROOT:getWorkspaceRoot(),
24-
}
10+
// Node env
11+
exporttypeEnv='test'|'local'|'development'|'production'
12+
//@ts-ignore
13+
exportconstNODE_ENV:Env=process.env.NODE_ENV||'production'
2514

26-
exportdefaultenvironment
15+
// toggle logging in development
16+
exportconstLOG:boolean=
17+
(process.env.REACT_APP_LOG||'').toLowerCase()==='true'&&process.env.NODE_ENV!=='production'
18+
19+
// error logging tool
20+
exportconstSENTRY_DSN:string|null=process.env.SENTRY_DSN||null
21+
22+
// uri path to the users project workspace
23+
exportconstWORKSPACE_ROOT:string=getWorkspaceRoot()

‎src/services/logger/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
importenviromentfrom'../../environment'
1+
import{LOG}from'../../environment'
22

33
constlogger=(message:string|string[])=>{
4-
if(!enviroment.LOG){
4+
if(!LOG){
55
return
66
}
77
if(Array.isArray(message)){

‎src/services/node/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { exec as cpExec } from 'child_process'
22
import*asfsfrom'fs'
33
import{join}from'path'
44
import{promisify}from'util'
5-
importenvironmentfrom'../../environment'
5+
import{WORKSPACE_ROOT}from'../../environment'
66

77
constasyncExec=promisify(cpExec)
88

99
exportconstexec=(cmd:string):Promise<{stdout:string;stderr:string}>|never=>{
1010
returnasyncExec(cmd,{
11-
cwd:environment.WORKSPACE_ROOT,
11+
cwd:WORKSPACE_ROOT,
1212
})
1313
}
1414

1515
exportconstexists=(...paths:string[]):boolean|never=>{
16-
returnfs.existsSync(join(environment.WORKSPACE_ROOT, ...paths))
16+
returnfs.existsSync(join(WORKSPACE_ROOT, ...paths))
1717
}

‎src/services/sentry/init.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import{init}from'@sentry/node'
2-
importenvironmentfrom'../../environment'
2+
import{SENTRY_DSN,NODE_ENV}from'../../environment'
33

4-
if(environment.SENTRY_DSN){
4+
if(SENTRY_DSN){
55
init({
6-
dsn:environment.SENTRY_DSN,
7-
environment:environment.NODE_ENV,
6+
dsn:SENTRY_DSN,
7+
environment:NODE_ENV,
88
})
99
}

‎src/services/sentry/onError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import*assentryfrom'@sentry/node'
22
// import { Scope } from '@sentry/hub'
3-
importenvironmentfrom'../../environment'
3+
import{VERSION}from'../../environment'
44

55
constonError=(error:Error)=>{
66
// set user scope https://docs.sentry.io/enriching-error-data/scopes/?platform=node
77
sentry.withScope((scope:any)=>{
8-
scope.setTag('VERSION',environment.VERSION)
8+
scope.setTag('VERSION',VERSION)
99
// if (user) {
1010
// scope.setUser({
1111
// id: user.id,

‎src/services/workspace/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asvscodefrom'vscode'
22
import*asfsfrom'fs'
33
import{promisify}from'util'
4-
importenvironmentfrom'../../environment'
4+
import{WORKSPACE_ROOT}from'../../environment'
55

66
constreadDir=promisify(fs.readdir)
77

@@ -13,7 +13,7 @@ export const openWorkspace = () => {
1313
exportconstcheckWorkspaceEmpty=async()=>{
1414
letfiles
1515
try{
16-
files=awaitreadDir(environment.WORKSPACE_ROOT)
16+
files=awaitreadDir(WORKSPACE_ROOT)
1717
}catch(error){
1818
thrownewError('Failed to check workspace')
1919
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp