Skip to content

Commit 4e1e1a5

Browse files
committed
send src logs to output channel
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent 389181f commit 4e1e1a5

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
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 * as T from 'typings'
2-
import { showOutput } from '../services/testRunner/output'
2+
import { showOutput } from '../services/logger/output'
33

44
export const onOpenLogs = async (action: T.Action): Promise<void> => {
55
const channel = action.payload.channel

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
export const NODE_ENV: Env = process.env.NODE_ENV || 'development'
1212

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

src/services/logger/index.ts

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

33
export type Log = any
44

5+
const logChannel = getOutputChannel('CodeRoad (Logs)')
6+
57
const logger = (...messages: Log[]): void => {
6-
if (!LOG) {
7-
return
8-
}
98
// Inside vscode, you console.log does not allow more than 1 param
109
// to get around it, we can log with multiple log statements
1110
for (const message of messages) {
1211
if (typeof message === 'object') {
13-
console.log(JSON.stringify(message))
12+
logChannel.appendLine(JSON.stringify(message))
1413
} else {
15-
console.log(message)
14+
logChannel.appendLine(message)
1615
}
1716
}
1817
}

src/services/testRunner/output.ts renamed 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-
const getOutputChannel = (name: string): vscode.OutputChannel => {
9+
export const getOutputChannel = (name: string): vscode.OutputChannel => {
1010
if (!channels[name]) {
1111
channels[name] = vscode.window.createOutputChannel(name)
1212
}

src/services/testRunner/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import parser, { ParserOutput } from './parser'
66
import parseSubtasks from './subtasks'
77
import { debounce, throttle } from './throttle'
88
import { onError } from '../telemetry'
9-
import { clearOutput, addOutput } from './output'
9+
import { clearOutput, addOutput } from '../logger/output'
1010
import { formatFailOutput } from './formatOutput'
1111

1212
interface Callbacks {
@@ -18,7 +18,6 @@ interface Callbacks {
1818
}
1919

2020
const failChannelName = 'CodeRoad (Tests)'
21-
const logChannelName = 'CodeRoad (Logs)'
2221

2322
interface TestRunnerParams {
2423
position: T.Position
@@ -91,7 +90,7 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks): ((params: an
9190

9291
const tap: ParserOutput = parser(stdout || '')
9392

94-
addOutput({ channel: logChannelName, text: tap.logs.join('\n'), show: false })
93+
logger(tap.logs.join('\n'))
9594

9695
if (stderr) {
9796
if (!tap.failed.length) {

0 commit comments

Comments
 (0)