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

Commit4e1a407

Browse files
authored
Feature/output channel (coderoad#557)
* send src logs to output channelSigned-off-by: shmck <shawn.j.mckay@gmail.com>* send logs from client to ext channelSigned-off-by: shmck <shawn.j.mckay@gmail.com>* cleanup onTutorialConfigContinue logSigned-off-by: shmck <shawn.j.mckay@gmail.com>* clean up test fail logsSigned-off-by: shmck <shawn.j.mckay@gmail.com>* cleanup init logsSigned-off-by: shmck <shawn.j.mckay@gmail.com>* update logging across appSigned-off-by: shmck <shawn.j.mckay@gmail.com>* only log non-trusted security warningsSigned-off-by: shmck <shawn.j.mckay@gmail.com>* clenaup error messagesSigned-off-by: shmck <shawn.j.mckay@gmail.com>* cleanup action logsSigned-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent389181f commit4e1a407

File tree

30 files changed

+126
-125
lines changed

30 files changed

+126
-125
lines changed

‎src/actions/onOpenLogs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asTfrom'typings'
2-
import{showOutput}from'../services/testRunner/output'
2+
import{showOutput}from'../services/logger/output'
33

44
exportconstonOpenLogs=async(action:T.Action):Promise<void>=>{
55
constchannel=action.payload.channel

‎src/actions/onRunReset.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Context from '../services/context/context'
44
importresetfrom'../services/reset'
55
import*ashooksfrom'../services/hooks'
66
importgetCommitHashByPositionfrom'../services/reset/lastHash'
7+
importloggerfrom'../services/logger'
78

89
typeResetAction={
910
type:'LATEST'|'POSITION'
@@ -22,7 +23,7 @@ const onRunReset = async (action: ResetAction, context: Context): Promise<void>
2223
constbranch=tutorial?.config.repo.branch
2324

2425
if(!branch){
25-
console.error('No repo branch found for tutorial')
26+
logger('Error:No repo branch found for tutorial')
2627
return
2728
}
2829

‎src/actions/onTutorialConfigContinue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import logger from '../services/logger'
88
import{setupWebhook}from'../services/hooks/webhooks'
99

1010
constonTutorialConfigContinue=async(action:T.Action,context:Context):Promise<void>=>{
11-
logger('onTutorialConfigContinue',action)
11+
logger(`Continuing tutorial from progress:${JSON.stringify(action.payload)}`)
1212
try{
1313
consttutorialToContinue:TT.Tutorial|null=context.tutorial.get()
1414
if(!tutorialToContinue){

‎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/commands.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ interface CreateCommandProps {
2121
}
2222

2323
letsendToClient=(action:T.Action):void=>{
24-
// function is replaced whenwebclient loads
24+
// function is replaced whenwebview mounts
2525
}
2626

2727
// This makes it easier to pass the send
2828
// function throughout the codebase
2929
exportconstsend=(action:T.Action):void=>{
30-
logger(`EXT TO CLIENT: "${typeofaction==='string' ?action :action.type}"`)
31-
32-
if(action)sendToClient(action)
30+
// log send of event to client
31+
logger(`${typeofaction==='string' ?action :action.type}`)
32+
sendToClient(action)
3333
}
3434

3535
exportconstcreateCommands=(commandProps:CreateCommandProps):{[key:string]:any}=>{
@@ -75,7 +75,7 @@ export const createCommands = (commandProps: CreateCommandProps): { [key: string
7575
}
7676
testRunner=createTestRunner(data,{
7777
onSuccess:(position:T.Position)=>{
78-
logger('test pass position',position)
78+
logger(`Test pass position:${JSON.stringify(position)}`)
7979
// send test pass message back to client
8080
channel.context.position.set({ ...position,complete:true})
8181
send({type:'TEST_PASS',payload:{position:{ ...position,complete:true}}})
@@ -91,7 +91,7 @@ export const createCommands = (commandProps: CreateCommandProps): { [key: string
9191
},
9292
onRun:(position:T.Position)=>{
9393
// send test run message back to client
94-
send({type:'TEST_RUNNING',payload:{ position}})
94+
send({type:'START_TEST',payload:{ position}})
9595
},
9696
onLoadSubtasks:({ summary})=>{
9797
send({type:'LOAD_SUBTASK_RESULTS',payload:{ summary}})

‎src/environment.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ export type Env = 'test' | 'local' | 'development' | 'production'
1010
//@ts-ignore
1111
exportconstNODE_ENV:Env=process.env.NODE_ENV||'development'
1212

13-
// toggle logging
14-
exportconstLOG=(process.env.CODEROAD_ENABLE_LOG||'').toLowerCase()==='true'
15-
1613
// error logging tool
1714
exportconstINSTRUMENTATION_KEY='6ff37c76-72f3-48e3-a1b9-d5636f519b7b'
1815

‎src/services/git/index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const stashAllFiles = async (): Promise<never | void> => {
99
// stash files including untracked (eg. newly created file)
1010
const{ stderr}=awaitexec({command:`git stash --include-untracked`})
1111
if(stderr){
12-
console.error(stderr)
12+
logger(`Error:${stderr}`)
1313
thrownewError('Error stashing files')
1414
}
1515
}
1616

1717
constcherryPickCommit=async(commit:string,count=0):Promise<never|void>=>{
1818
if(count>1){
19-
console.warn('cherry-pick failed')
19+
logger('cherry-pick failed')
2020
return
2121
}
2222
try{
@@ -26,8 +26,8 @@ const cherryPickCommit = async (commit: string, count = 0): Promise<never | void
2626
if(!stdout){
2727
thrownewError('No cherry-pick output')
2828
}
29-
}catch(error){
30-
console.log('cherry-pick-commit failed')
29+
}catch(error:any){
30+
logger(`cherry-pick-commit failed:${error.message}`)
3131
// stash all files if cherry-pick fails
3232
awaitstashAllFiles()
3333
returncherryPickCommit(commit,++count)
@@ -50,10 +50,10 @@ export function loadCommit(commit: string): Promise<never | void> {
5050
exportasyncfunctionsaveCommit(message:string):Promise<never|void>{
5151
const{ stdout, stderr}=awaitexec({command:`git commit -am '${message}'`})
5252
if(stderr){
53-
console.error(stderr)
53+
logger(`Error:${stderr}`)
5454
thrownewError('Error saving progress to Git')
5555
}
56-
logger(['save with commit & continuestdout',stdout])
56+
logger(`Commit saved:${stdout}`)
5757
}
5858

5959
exportasyncfunctionclear():Promise<Error|void>{
@@ -63,9 +63,9 @@ export async function clear(): Promise<Error | void> {
6363
if(!stderr){
6464
return
6565
}
66-
console.error(stderr)
67-
}catch(error){
68-
console.error(error)
66+
logger(`Error:${stderr}`)
67+
}catch(error:any){
68+
logger(`Error:${error.message}`)
6969
}
7070
thrownewError('Error cleaning up current unsaved work')
7171
}
@@ -127,7 +127,7 @@ export async function addRemote(repo: string): Promise<never | void> {
127127

128128
// validate the response is acceptable
129129
if(!alreadyExists&&!successfulNewBranch){
130-
console.error(stderr)
130+
logger(`Error:${stderr}`)
131131
thrownewError('Error adding git remote')
132132
}
133133
}
@@ -142,7 +142,8 @@ export async function checkRemoteExists(): Promise<boolean> {
142142
// string match on remote output
143143
// TODO improve the specificity of this regex
144144
return!!stdout.match(gitOrigin)
145-
}catch(error){
145+
}catch(error:any){
146+
logger(`Warn:${error.message}`)
146147
returnfalse
147148
}
148149
}
@@ -168,8 +169,9 @@ export async function loadCommitHistory(): Promise<string[]> {
168169
}
169170
// string match on remote output
170171
returnstdout.split('\n')
171-
}catch(error){
172+
}catch(error:any){
172173
// likely no git setup or no commits
174+
logger(`Warn:${error.message}`)
173175
return[]
174176
}
175177
}
@@ -189,8 +191,8 @@ export async function getCommitMessage(hash: string): Promise<string | null> {
189191
}
190192
// string match on remote output
191193
returnstdout
192-
}catch(error){
193-
logger('error',error)
194+
}catch(error:any){
195+
logger(`Error:${error.message}`)
194196
// likely no git commit message found
195197
returnnull
196198
}
@@ -204,8 +206,8 @@ export async function commitsExistsByMessage(message: string): Promise<boolean>
204206
returnfalse
205207
}
206208
return!!stdout.length
207-
}catch(error){
208-
logger('error',error)
209+
}catch(error:any){
210+
logger(`Error:${error.message}`)
209211
// likely no commit found
210212
returnfalse
211213
}

‎src/services/hooks/utils/openFiles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import{join}from'path'
22
import*asvscodefrom'vscode'
3+
importloggerfrom'../../logger'
34

45
constopenFiles=async(files:string[]=[]):Promise<void>=>{
56
if(!files.length){
@@ -16,7 +17,7 @@ const openFiles = async (files: string[] = []): Promise<void> => {
1617
constdoc=awaitvscode.workspace.openTextDocument(absoluteFilePath)
1718
awaitvscode.window.showTextDocument(doc,vscode.ViewColumn.One)
1819
}catch(error:any){
19-
console.log(`Failed to open file${filePath}:${error.message}`)
20+
logger(`Failed to open file${filePath}:${error.message}`)
2021
}
2122
}
2223
}

‎src/services/hooks/utils/runCommands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import{exec}from'../../node'
22
import{send}from'../../../commands'
3+
importloggerfrom'../../logger'
34

45
construnCommands=async(commands:string[]=[]):Promise<void>=>{
56
if(!commands.length){
@@ -14,9 +15,9 @@ const runCommands = async (commands: string[] = []): Promise<void> => {
1415
letresult:{stdout:string;stderr:string}
1516
try{
1617
result=awaitexec({ command})
17-
console.log(result)
18+
logger(`Command output:${JSON.stringify(result)}`)
1819
}catch(error:any){
19-
console.error(`Command failed:${error.message}`)
20+
logger(`Command failed:${error.message}`)
2021
send({type:'COMMAND_FAIL',payload:{process:{ ...process,status:'FAIL'}}})
2122
return
2223
}

‎src/services/logger/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import{LOG}from'../../environment'
1+
import{getOutputChannel}from'./output'
22

33
exporttypeLog=any
44

5+
constlogChannel=getOutputChannel('CodeRoad (Logs)')
6+
57
constlogger=(...messages:Log[]):void=>{
6-
if(!LOG){
7-
return
8-
}
9-
// Inside vscode, you console.log does not allow more than 1 param
10-
// to get around it, we can log with multiple log statements
118
for(constmessageofmessages){
129
if(typeofmessage==='object'){
13-
console.log(JSON.stringify(message))
10+
logChannel.appendLine(message)
1411
}else{
15-
console.log(message)
12+
logChannel.appendLine(message)
1613
}
1714
}
1815
}

‎src/services/testRunner/output.tsrenamed to‎src/services/logger/output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const channels:
66
/* */
77
}={}
88

9-
constgetOutputChannel=(name:string):vscode.OutputChannel=>{
9+
exportconstgetOutputChannel=(name:string):vscode.OutputChannel=>{
1010
if(!channels[name]){
1111
channels[name]=vscode.window.createOutputChannel(name)
1212
}

‎src/services/node/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'fs'
33
import{join}from'path'
44
import{promisify}from'util'
55
import{WORKSPACE_ROOT}from'../../environment'
6+
importloggerfrom'../logger'
67

78
constasyncExec=promisify(cpExec)
89
constasyncRemoveFile=promisify(fs.unlink)
@@ -35,13 +36,13 @@ export const removeFile = (...paths: string[]) => {
3536
exportconstreadFile=(...paths:string[]):Promise<string|void>=>{
3637
constfilePath=getWorkspacePath(...paths)
3738
returnasyncReadFile(getWorkspacePath(...paths),'utf8').catch((err)=>{
38-
console.warn(`Failed to read from${filePath}:${err.message}`)
39+
logger(`Failed to read from${filePath}:${err.message}`)
3940
})
4041
}
4142

4243
exportconstwriteFile=(data:any, ...paths:string[]):Promise<void>=>{
4344
constfilePath=getWorkspacePath(...paths)
4445
returnasyncWriteFile(filePath,data).catch((err)=>{
45-
console.warn(`Failed to write to${filePath}:${err.message}`)
46+
logger(`Failed to write to${filePath}:${err.message}`)
4647
})
4748
}

‎src/services/reset/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{exec,removeFile}from'../node'
2-
2+
importloggerfrom'../logger'
33
interfaceInput{
44
hash:string
55
branch:string
@@ -17,13 +17,13 @@ const reset = async ({ branch, hash }: Input): Promise<void> => {
1717
try{
1818
// if no git init, will initialize
1919
// otherwise re-initializes git
20-
awaitexec({command:'git init'}).catch(console.log)
20+
awaitexec({command:'git init'}).catch(logger)
2121

2222
// capture current branch
2323
consthasBranch=awaitexec({command:'git branch --show-current'})
2424
constlocalBranch=hasBranch.stdout
2525
// check if coderoad remote exists
26-
consthasRemote=awaitexec({command:'git remote -v'}).catch(console.warn)
26+
consthasRemote=awaitexec({command:'git remote -v'}).catch(logger)
2727
if(!hasRemote||!hasRemote.stdout||!hasRemote.stdout.length){
2828
thrownewError('No remote found')
2929
}elseif(!hasRemote.stdout.match(newRegExp(remote))){
@@ -64,8 +64,7 @@ const reset = async ({ branch, hash }: Input): Promise<void> => {
6464
command:`git reset --hard${hash}`,
6565
})
6666
}catch(error:any){
67-
console.error('Error resetting')
68-
console.error(error.message)
67+
logger(`Error resetting:${error.message}`)
6968
}
7069
}
7170

‎src/services/storage/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import*asvscodefrom'vscode'
22
import{readFile,writeFile}from'../node'
33
import{SESSION_STORAGE_PATH}from'../../environment'
4+
importloggerfrom'../logger'
45

56
// NOTE: localStorage is not available on client
67
// and must be stored in editor
@@ -46,17 +47,17 @@ class Storage<T> {
4647
returndata
4748
}
4849
}
49-
}catch(err){
50-
console.warn(`Failed to read or parse session file:${SESSION_STORAGE_PATH}/${this.filePath}.json`)
50+
}catch(err:any){
51+
logger(`Failed to read or parse session file:${SESSION_STORAGE_PATH}/${this.filePath}.json:${err.message}`)
5152
}
5253
}
5354
constvalue:string|undefined=awaitthis.storage.get(this.key)
5455
if(value){
5556
// 2. read from local storage
5657
try{
5758
returnJSON.parse(value)
58-
}catch(err){
59-
console.warn(`Failed to parse session state from local storage:${value}`)
59+
}catch(err:any){
60+
logger(`Failed to parse session state from local storage:${value}:${err.message}`)
6061
}
6162
}
6263
// 3. fallback to the default
@@ -83,7 +84,9 @@ class Storage<T> {
8384
try{
8485
writeFile(data,SESSION_STORAGE_PATH,`${this.filePath}.json`)
8586
}catch(err:any){
86-
console.warn(`Failed to write coderoad session to path:${SESSION_STORAGE_PATH}/${this.filePath}.json`)
87+
logger(
88+
`Failed to write coderoad session to path:${SESSION_STORAGE_PATH}/${this.filePath}.json:${err.message}`,
89+
)
8790
}
8891
}
8992
}

‎src/services/telemetry/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface Measurements {
1919
letreporter:any
2020

2121
exportconstactivate=(subscribeFn:(reporter:any)=>void):void=>{
22-
logger(EXTENSION_ID,VERSION,INSTRUMENTATION_KEY)
22+
logger(`${EXTENSION_ID} v${VERSION}`)
2323
reporter=newTelemetryReporter(EXTENSION_ID,VERSION,INSTRUMENTATION_KEY)
2424
subscribeFn(reporter)
2525
}
@@ -31,14 +31,12 @@ export const deactivate = (): void => {
3131
}
3232

3333
exportconstonError=(error:Error,properties?:Properties,measurements?:Measurements):void=>{
34-
logger(error,properties,measurements)
3534
if(reporter){
3635
reporter.sendTelemetryException(error,properties,measurements)
3736
}
3837
}
3938

4039
exportconstonEvent=(eventName:string,properties?:Properties,measurements?:Measurements):void=>{
41-
logger(eventName,properties,measurements)
4240
if(reporter){
4341
reporter.sendTelemetryEvent(eventName,properties,measurements)
4442
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp