Skip to content

Commit

Permalink
Added basic logging service to wrap output window usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jakenuts committed Dec 9, 2024
1 parent 7559228 commit 2df14e7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 17,191 deletions.
10 changes: 10 additions & 0 deletions claude-dev.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"typescript.tsc.autoDetect": "off"
}
}
9 changes: 7 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ClineProvider } from "./core/webview/ClineProvider"
import { createClineAPI } from "./exports"
import "./utils/path" // necessary to have access to String.prototype.toPosix
import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
import { LoggerService } from "./services/logging/LoggerService"

/*
Built using https://github.com/microsoft/vscode-webview-ui-toolkit
Expand All @@ -21,12 +22,16 @@ let outputChannel: vscode.OutputChannel
// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
const logger = LoggerService.getInstance()
context.subscriptions.push(logger.getOutputChannel())
logger.log("Cline extension activated", "Extension")

outputChannel = vscode.window.createOutputChannel("Cline")
context.subscriptions.push(outputChannel)

outputChannel.appendLine("Cline extension activated")

const sidebarProvider = new ClineProvider(context, outputChannel)
const sidebarProvider = new ClineProvider(context, logger.getOutputChannel())

context.subscriptions.push(
vscode.window.registerWebviewViewProvider(ClineProvider.sideBarId, sidebarProvider, {
Expand Down Expand Up @@ -135,5 +140,5 @@ export function activate(context: vscode.ExtensionContext) {

// This method is called when your extension is deactivated
export function deactivate() {
outputChannel.appendLine("Cline extension deactivated")
LoggerService.getInstance().log("Cline extension deactivated", "Extension")
}
12 changes: 6 additions & 6 deletions src/services/curation/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LoggerService } from '../logging/LoggerService';

interface CurationConfig {
maxRows?: number;
maxTotalChars?: number;
Expand All @@ -6,6 +8,7 @@ interface CurationConfig {
}

export class Curation {
private static readonly logger = LoggerService.getInstance();
// Default configurations for different content types
private static readonly DEFAULTS = {
CONSOLE_LOGS: {
Expand Down Expand Up @@ -42,14 +45,11 @@ export class Curation {
truncationMessage = Curation.DEFAULTS.CONSOLE_LOGS.truncationMessage
} = config;



// If within limits, return original array
if (items.length <= maxRows) {
const totalChars = items.reduce((sum, item) => sum + item.length, 0);
if (totalChars <= maxTotalChars) {

console.log(`[Curation] Content approved ${items.length} lines of ${totalChars} chars.`);
this.logger.logOperation('Curation', 'Content approved', `${items.length} lines of ${totalChars} chars`);
return items;
}
}
Expand All @@ -61,7 +61,7 @@ export class Curation {
const firstPart = items.slice(0, keepEdges);
const lastPart = items.slice(-keepEdges);

console.log(`[Curation] Content truncated, ${removedCount} of ${items.length} lines removed.`);
this.logger.logOperation('Curation', 'Content truncated', `${removedCount} of ${items.length} lines removed`);

return [
...firstPart,
Expand All @@ -81,7 +81,7 @@ export class Curation {
if (currentSize >= maxTotalChars) {
const removedCount = endIndex - startIndex + 1;

console.log(`[Curation] Content truncated, ${removedCount} of ${currentSize} chars removed.`);
this.logger.logOperation('Curation', 'Content truncated', `${removedCount} of ${currentSize} chars removed`);

if (removedCount > 0) {
truncatedItems.splice(
Expand Down
71 changes: 71 additions & 0 deletions src/services/logging/LoggerService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Centralized logging service for the extension.
* Provides a singleton instance for consistent logging across all services.
*
* Usage:
* ```ts
* const logger = LoggerService.getInstance();
* logger.log("Message", "ServiceName");
* ```
*/

import * as vscode from "vscode"

export class LoggerService {
private static instance: LoggerService
private outputChannel: vscode.OutputChannel
private disposed = false

private constructor() {
this.outputChannel = vscode.window.createOutputChannel("Cline")
}

public static getInstance(): LoggerService {
if (!LoggerService.instance) {
LoggerService.instance = new LoggerService()
}
return LoggerService.instance
}

/**
* Log a message with optional source identifier
* @param message The message to log
* @param source Optional source identifier (e.g. service name)
*/
public log(message: string, source?: string) {
if (this.disposed) return;
const timestamp = new Date().toISOString()
const prefix = source ? `[${source}]` : ""
this.outputChannel.appendLine(`${timestamp} ${prefix} ${message}`)
}

/**
* Get the underlying VS Code OutputChannel
* For use in extension.ts to register for disposal
*/
public getOutputChannel(): vscode.OutputChannel {
return this.outputChannel
}

/**
* Dispose of the output channel
* Should only be called when the extension is deactivated
*/
public dispose() {
if (!this.disposed) {
this.disposed = true
this.outputChannel.dispose()
}
}

/**
* Log a service operation with details
* @param service The service name
* @param operation The operation being performed
* @param details Optional additional details
*/
public logOperation(service: string, operation: string, details?: string) {
const message = details ? `${operation}: ${details}` : operation
this.log(message, service)
}
}
Loading

0 comments on commit 2df14e7

Please sign in to comment.