@@ -20,7 +20,7 @@ The vscode-coder extension currently handles logging through the Storage class,
2020 - No ` any ` types in the logger module or modified files
2121 - No ` @ts-ignore ` or ` eslint-disable ` comments
2222 - All types explicitly defined or properly inferred
23- 4 . ** Testable** :
23+ 4 . ** Testable** :
2424 - Unit tests use ` ArrayAdapter ` for fast, isolated testing
2525 - ArrayAdapter provides immutable snapshots via ` getSnapshot() ` to prevent test interference
2626 - Integration tests use ` OutputChannelAdapter ` to verify VS Code integration
@@ -53,6 +53,7 @@ The vscode-coder extension currently handles logging through the Storage class,
5353## Scope & Constraints
5454
5555### In Scope
56+
5657- Extract logging functionality from the Storage class into a dedicated logging adapter
5758- Create a logging adapter/service with support for debug and info levels
5859- Convert all existing ` writeToCoderOutputChannel ` and ` output.appendLine ` calls to use the adapter
@@ -69,6 +70,7 @@ The vscode-coder extension currently handles logging through the Storage class,
6970- Remove only the ` writeToCoderOutputChannel ` method from Storage class
7071
7172### Out of Scope
73+
7274- External logging services integration (future enhancement)
7375- File-based logging (all logs go to VS Code OutputChannel)
7476- Log file rotation or persistence
@@ -81,6 +83,7 @@ The vscode-coder extension currently handles logging through the Storage class,
8183## Technical Considerations
8284
8385### Architecture
86+
8487- Singleton pattern for the logger instance
8588- Interface-based design with pluggable adapters:
8689 - ` LogAdapter ` interface for output handling
@@ -106,80 +109,81 @@ The vscode-coder extension currently handles logging through the Storage class,
106109- ** Centralized formatting** : All log formatting (timestamps, level tags, source location) happens within the logger implementation, not at call sites
107110
108111### API Design
112+
109113``` typescript
110114interface LogAdapter {
111- write(message : string ): void
112- clear(): void
115+ write(message : string ): void ;
116+ clear(): void ;
113117}
114118
115119interface Logger {
116- log(message : string , severity ? : LogLevel ): void // Core method, defaults to INFO
117- debug(message : string ): void // String only - no object serialization
118- info(message : string ): void // String only - no object serialization
119- setLevel(level : LogLevel ): void
120- setAdapter(adapter : LogAdapter ): void // For testing only - throws if adapter already set
121- withAdapter<T >(adapter : LogAdapter , fn : () => T ): T // Safe temporary adapter swap
122- reset(): void // For testing only - throws if NODE_ENV !== 'test', disposes listeners
120+ log(message : string , severity ? : LogLevel ): void ; // Core method, defaults to INFO
121+ debug(message : string ): void ; // String only - no object serialization
122+ info(message : string ): void ; // String only - no object serialization
123+ setLevel(level : LogLevel ): void ;
124+ setAdapter(adapter : LogAdapter ): void ; // For testing only - throws if adapter already set
125+ withAdapter<T >(adapter : LogAdapter , fn : () => T ): T ; // Safe temporary adapter swap
126+ reset(): void ; // For testing only - throws if NODE_ENV !== 'test', disposes listeners
123127}
124128
125129enum LogLevel {
126- DEBUG = 0 ,
127- INFO = 1 ,
128- NONE = 2 // Disables all logging
130+ DEBUG = 0 ,
131+ INFO = 1 ,
132+ NONE = 2 , // Disables all logging
129133}
130134
131135// Example implementations
132136class OutputChannelAdapter implements LogAdapter {
133- constructor (private outputChannel : vscode .OutputChannel ) {}
134- write(message : string ): void {
135- try {
136- this .outputChannel .appendLine (message )
137- } catch {
138- // Silently ignore - channel may be disposed
139- }
140- }
141- clear(): void {
142- try {
143- this .outputChannel .clear ()
144- } catch {
145- // Silently ignore - channel may be disposed
146- }
147- }
137+ constructor (private outputChannel : vscode .OutputChannel ) {}
138+ write(message : string ): void {
139+ try {
140+ this .outputChannel .appendLine (message );
141+ } catch {
142+ // Silently ignore - channel may be disposed
143+ }
144+ }
145+ clear(): void {
146+ try {
147+ this .outputChannel .clear ();
148+ } catch {
149+ // Silently ignore - channel may be disposed
150+ }
151+ }
148152}
149153
150154class ArrayAdapter implements LogAdapter {
151- private logs: string [] = []
152-
153- write(message : string ): void {
154- this .logs .push (message )
155- }
156-
157- clear(): void {
158- this .logs = []
159- }
160-
161- getSnapshot(): readonly string [] {
162- return [... this .logs ] // Return defensive copy
163- }
155+ private logs: string [] = [];
156+
157+ write(message : string ): void {
158+ this .logs .push (message );
159+ }
160+
161+ clear(): void {
162+ this .logs = [];
163+ }
164+
165+ getSnapshot(): readonly string [] {
166+ return [... this .logs ]; // Return defensive copy
167+ }
164168}
165169
166170class NoOpAdapter implements LogAdapter {
167- write(message : string ): void {
168- // Intentionally empty - baseline for performance tests
169- }
170-
171- clear(): void {
172- // Intentionally empty - baseline for performance tests
173- }
171+ write(message : string ): void {
172+ // Intentionally empty - baseline for performance tests
173+ }
174+
175+ clear(): void {
176+ // Intentionally empty - baseline for performance tests
177+ }
174178}
175179```
176180
177181### Log Format
182+
178183- ** Standard format** : ` [LEVEL] TIMESTAMP MESSAGE `
179184 - Timestamp in UTC ISO-8601 format (e.g., ` 2024-01-15T10:30:45.123Z ` )
180185 - Example: ` [info] 2024-01-15T10:30:45.123Z Starting extension... `
181186 - Example: ` [debug] 2024-01-15T10:30:45.456Z Processing file: example.ts `
182-
183187- ** Debug mode enhancement** : When ` coder.verbose ` is true, debug logs include source location:
184188 ```
185189 [debug] 2024-01-15T10:30:45.456Z Processing file: example.ts
@@ -238,7 +242,7 @@ class NoOpAdapter implements LogAdapter {
2382429. Run linting (`yarn lint `) and ensure code quality
239243
240244### File Locations
245+
241246- Logger implementation : `src /logger .ts `
242247- Tests : `src /logger .test .ts `
243248- Type definitions included in the logger file
244-
0 commit comments