Skip to content

Commit a833b08

Browse files
committed
Modified logging slightly
1 parent bb1c063 commit a833b08

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

src/extension.ts

+28-23
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,40 @@ export function activate(context: vscode.ExtensionContext) {
4242

4343
}
4444

45+
export enum LogLevel {
46+
Info = 'INF',
47+
Warn = 'WRN',
48+
Error = 'ERR'
49+
}
50+
4551
/**
4652
* Prints the given content on the output channel.
4753
*
4854
* @param content The content to be printed.
55+
* @param verbose Whether this should be included only in verbose logging
4956
* @param reveal Whether the output channel should be revealed.
57+
* @param level The log level for the output.
5058
*/
51-
export const printChannelOutput = (content: string, verbose: boolean, reveal = false): void => {
52-
53-
// do not throw on logging, just log to console in the event of an error
54-
try {
55-
if (!outputChannel) {
56-
return;
57-
}
58-
// if it is verbose logging and verbose is not enabled, return
59-
if (verbose && !vscode.workspace.getConfiguration("resx-editor").get("verboseLogging")) {
60-
return;
61-
}
62-
63-
const timestamp = new Date().toISOString();
64-
65-
outputChannel.appendLine(`[${timestamp}] ${content}`);
66-
67-
if (reveal) {
68-
outputChannel.show(true);
69-
}
70-
}
71-
catch (e) {
72-
console.log(e);
73-
}
59+
export const printChannelOutput = (content: string, verbose: boolean, reveal = false, level: LogLevel = LogLevel.Info): void => {
60+
try {
61+
if (!outputChannel) {
62+
return;
63+
}
64+
if (verbose && !vscode.workspace.getConfiguration("resx-editor").get("verboseLogging")) {
65+
return;
66+
}
67+
68+
const timestamp = new Date().toISOString();
69+
70+
outputChannel.appendLine(`[${timestamp}] [${level}] ${content}`);
71+
72+
if (reveal) {
73+
outputChannel.show(true);
74+
}
75+
}
76+
catch (e) {
77+
console.log(e);
78+
}
7479
};
7580

7681
export function deactivate() { }

src/resxProvider.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import * as resx from 'resx';
33
import * as path from 'path';
44
import { getNonce } from './utilities/getNonce';
5-
import { printChannelOutput } from './extension';
5+
import { LogLevel, printChannelOutput } from './extension';
66
import { newResourceInput } from './addNewResource';
77
import { AppConstants } from './utilities/constants';
88
import { generateAndUpdateDesignerFile } from './utilities/generateCode';
@@ -105,7 +105,7 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
105105
printChannelOutput(e.message, true);
106106
return;
107107
case 'error':
108-
printChannelOutput(e.message, true);
108+
printChannelOutput(e.message, true, true, LogLevel.Error);
109109
vscode.window.showErrorMessage(e.message);
110110
return;
111111
case 'info':
@@ -151,13 +151,13 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
151151
const generateCode = config.get<boolean>('generateCode', true);
152152
printChannelOutput(`Successfully updated RESX${generateCode ? ' and Designer' : ''} files`, true);
153153
} else {
154-
printChannelOutput(`Failed to apply workspace edits`, true);
154+
printChannelOutput(`Failed to apply workspace edits`, true, true, LogLevel.Error);
155155
vscode.window.showErrorMessage('Failed to update resource files');
156156
}
157157
return success;
158158
} catch (error) {
159159
const errorMessage = `Error updating resource files: ${error instanceof Error ? error.message : String(error)}`;
160-
printChannelOutput(errorMessage, true);
160+
printChannelOutput(errorMessage, true, true, LogLevel.Error);
161161
vscode.window.showErrorMessage(errorMessage);
162162
return false;
163163
}

0 commit comments

Comments
 (0)