Add simple backend logging service (#1517)

* formatting

* inefficient import

* remove redundant initialization check
This commit is contained in:
Evan Fannin 2025-01-29 06:45:13 +08:00 committed by GitHub
parent 142029b09f
commit fc5d0bdb5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

View file

@ -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")
}

View file

@ -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)
}
}