Skip to content

Feature/output channel #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 3, 2022
Next Next commit
send src logs to output channel
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jan 2, 2022
commit 4e1e1a562f57e3cadc875b08f4a20f2b037940a2
2 changes: 1 addition & 1 deletion src/actions/onOpenLogs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as T from 'typings'
import { showOutput } from '../services/testRunner/output'
import { showOutput } from '../services/logger/output'

export const onOpenLogs = async (action: T.Action): Promise<void> => {
const channel = action.payload.channel
Expand Down
3 changes: 0 additions & 3 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export type Env = 'test' | 'local' | 'development' | 'production'
// @ts-ignore
export const NODE_ENV: Env = process.env.NODE_ENV || 'development'

// toggle logging
export const LOG = (process.env.CODEROAD_ENABLE_LOG || '').toLowerCase() === 'true'

// error logging tool
export const INSTRUMENTATION_KEY = '6ff37c76-72f3-48e3-a1b9-d5636f519b7b'

Expand Down
11 changes: 5 additions & 6 deletions src/services/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { LOG } from '../../environment'
import { getOutputChannel } from './output'

export type Log = any

const logChannel = getOutputChannel('CodeRoad (Logs)')

const logger = (...messages: Log[]): void => {
if (!LOG) {
return
}
// Inside vscode, you console.log does not allow more than 1 param
// to get around it, we can log with multiple log statements
for (const message of messages) {
if (typeof message === 'object') {
console.log(JSON.stringify(message))
logChannel.appendLine(JSON.stringify(message))
} else {
console.log(message)
logChannel.appendLine(message)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const channels:
/* */
} = {}

const getOutputChannel = (name: string): vscode.OutputChannel => {
export const getOutputChannel = (name: string): vscode.OutputChannel => {
if (!channels[name]) {
channels[name] = vscode.window.createOutputChannel(name)
}
Expand Down
5 changes: 2 additions & 3 deletions src/services/testRunner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import parser, { ParserOutput } from './parser'
import parseSubtasks from './subtasks'
import { debounce, throttle } from './throttle'
import { onError } from '../telemetry'
import { clearOutput, addOutput } from './output'
import { clearOutput, addOutput } from '../logger/output'
import { formatFailOutput } from './formatOutput'

interface Callbacks {
Expand All @@ -18,7 +18,6 @@ interface Callbacks {
}

const failChannelName = 'CodeRoad (Tests)'
const logChannelName = 'CodeRoad (Logs)'

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

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

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

if (stderr) {
if (!tap.failed.length) {
Expand Down