diff --git a/src/extension.ts b/src/extension.ts index 1faee0133b..ed9cff31e9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,7 @@ import delay from "delay" import * as vscode from "vscode" import { ClineProvider } from "./core/webview/ClineProvider" +import { Logger } from "./services/logging/Logger" import { createClineAPI } from "./exports" import "./utils/path" // necessary to have access to String.prototype.toPosix import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider" @@ -24,7 +25,8 @@ export function activate(context: vscode.ExtensionContext) { outputChannel = vscode.window.createOutputChannel("Cline") context.subscriptions.push(outputChannel) - outputChannel.appendLine("Cline extension activated") + Logger.initialize(outputChannel) + Logger.log("Cline extension activated") const sidebarProvider = new ClineProvider(context, outputChannel) @@ -36,7 +38,7 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand("cline.plusButtonClicked", async () => { - outputChannel.appendLine("Plus button Clicked") + Logger.log("Plus button Clicked") await sidebarProvider.clearTask() await sidebarProvider.postStateToWebview() await sidebarProvider.postMessageToWebview({ @@ -56,7 +58,7 @@ export function activate(context: vscode.ExtensionContext) { ) const openClineInNewTab = async () => { - outputChannel.appendLine("Opening Cline in new tab") + Logger.log("Opening Cline in new tab") // (this example uses webviewProvider activation event which is necessary to deserialize cached webview, but since we use retainContextWhenHidden, we don't need to use that event) // https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts const tabProvider = new ClineProvider(context, outputChannel) @@ -186,5 +188,5 @@ export function activate(context: vscode.ExtensionContext) { // This method is called when your extension is deactivated export function deactivate() { - outputChannel.appendLine("Cline extension deactivated") + Logger.log("Cline extension deactivated") } diff --git a/src/services/logging/Logger.ts b/src/services/logging/Logger.ts new file mode 100644 index 0000000000..0c94952ae6 --- /dev/null +++ b/src/services/logging/Logger.ts @@ -0,0 +1,18 @@ +import type { OutputChannel } from "vscode" + +/** + * Simple logging utility for the extension's backend code. + * Uses VS Code's OutputChannel which must be initialized from extension.ts + * to ensure proper registration with the extension context. + */ +export class Logger { + private static outputChannel: OutputChannel + + static initialize(outputChannel: OutputChannel) { + Logger.outputChannel = outputChannel + } + + static log(message: string) { + Logger.outputChannel.appendLine(message) + } +}