@@ -20,7 +20,7 @@ The vscode-coder extension currently handles logging through the Storage class,
20
20
- No ` any ` types in the logger module or modified files
21
21
- No ` @ts-ignore ` or ` eslint-disable ` comments
22
22
- All types explicitly defined or properly inferred
23
- 4 . ** Testable** :
23
+ 4 . ** Testable** :
24
24
- Unit tests use ` ArrayAdapter ` for fast, isolated testing
25
25
- ArrayAdapter provides immutable snapshots via ` getSnapshot() ` to prevent test interference
26
26
- Integration tests use ` OutputChannelAdapter ` to verify VS Code integration
@@ -53,6 +53,7 @@ The vscode-coder extension currently handles logging through the Storage class,
53
53
## Scope & Constraints
54
54
55
55
### In Scope
56
+
56
57
- Extract logging functionality from the Storage class into a dedicated logging adapter
57
58
- Create a logging adapter/service with support for debug and info levels
58
59
- 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,
69
70
- Remove only the ` writeToCoderOutputChannel ` method from Storage class
70
71
71
72
### Out of Scope
73
+
72
74
- External logging services integration (future enhancement)
73
75
- File-based logging (all logs go to VS Code OutputChannel)
74
76
- Log file rotation or persistence
@@ -81,6 +83,7 @@ The vscode-coder extension currently handles logging through the Storage class,
81
83
## Technical Considerations
82
84
83
85
### Architecture
86
+
84
87
- Singleton pattern for the logger instance
85
88
- Interface-based design with pluggable adapters:
86
89
- ` LogAdapter ` interface for output handling
@@ -106,80 +109,81 @@ The vscode-coder extension currently handles logging through the Storage class,
106
109
- ** Centralized formatting** : All log formatting (timestamps, level tags, source location) happens within the logger implementation, not at call sites
107
110
108
111
### API Design
112
+
109
113
``` typescript
110
114
interface LogAdapter {
111
- write(message : string ): void
112
- clear(): void
115
+ write(message : string ): void ;
116
+ clear(): void ;
113
117
}
114
118
115
119
interface 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
123
127
}
124
128
125
129
enum 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
129
133
}
130
134
131
135
// Example implementations
132
136
class 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
+ }
148
152
}
149
153
150
154
class 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
+ }
164
168
}
165
169
166
170
class 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
+ }
174
178
}
175
179
```
176
180
177
181
### Log Format
182
+
178
183
- ** Standard format** : ` [LEVEL] TIMESTAMP MESSAGE `
179
184
- Timestamp in UTC ISO-8601 format (e.g., ` 2024-01-15T10:30:45.123Z ` )
180
185
- Example: ` [info] 2024-01-15T10:30:45.123Z Starting extension... `
181
186
- Example: ` [debug] 2024-01-15T10:30:45.456Z Processing file: example.ts `
182
-
183
187
- ** Debug mode enhancement** : When ` coder.verbose ` is true, debug logs include source location:
184
188
```
185
189
[debug] 2024-01-15T10:30:45.456Z Processing file: example.ts
@@ -238,7 +242,7 @@ class NoOpAdapter implements LogAdapter {
238
242
9. Run linting (`yarn lint `) and ensure code quality
239
243
240
244
### File Locations
245
+
241
246
- Logger implementation : `src /logger .ts `
242
247
- Tests : `src /logger .test .ts `
243
248
- Type definitions included in the logger file
244
-
0 commit comments