Skip to content

Commit 8ad3878

Browse files
committed
Update README & improve logging
1 parent 94ce4b1 commit 8ad3878

File tree

8 files changed

+31
-12
lines changed

8 files changed

+31
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
A VS Code extension to manage Entity Framework migrations.
66

7-
![Entity Framework Migrations](images/treeview-screenshot.png)
7+
<img src="./images/treeview-screenshot.png" style="max-width:460px" alt="Entity Framework Migrations" />
88

99
## Features
1010

images/treeview-screenshot.png

-54.3 KB
Loading

src/cli/CLI.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export class CLI {
3737
);
3838
}
3939

40+
public static removeInfoPrefixFromStdErr(stdErr: string): string {
41+
return stdErr
42+
.split(NEWLINE_SEPARATOR)
43+
.filter(line => !line.startsWith('info:'))
44+
.join('\n');
45+
}
46+
4047
public static removePrefixFromStdOut(output: string): string {
4148
return output
4249
.split(NEWLINE_SEPARATOR)
@@ -88,8 +95,7 @@ export class CLI {
8895
cmd?.on('exit', async code => {
8996
const error = stderr || CLI.getErrorsFromStdOut(stdout);
9097
if (error || code !== 0) {
91-
const finalError = error || stdout;
92-
this.logger.error(finalError);
98+
const finalError = CLI.removeInfoPrefixFromStdErr(error || stdout);
9399
rej(new Error(finalError));
94100
} else {
95101
res(stdout);

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function activate(_context: vscode.ExtensionContext) {
1919
const textDocumentProvider = new TextDocumentProvider();
2020
const migrationTreeItemDecorationProvider =
2121
new MigrationTreeItemDecorationProvider();
22-
const treeDataProvider = new TreeDataProvider(projectFiles, cli);
22+
const treeDataProvider = new TreeDataProvider(logger, projectFiles, cli);
2323
const terminalProvider = new TerminalProvider(new Terminal(cli));
2424
const commandProvider = new CommandProvider(
2525
treeDataProvider,
@@ -32,6 +32,7 @@ export async function activate(_context: vscode.ExtensionContext) {
3232
terminalProvider,
3333
textDocumentProvider,
3434
);
35+
logger.info(`extension activated`);
3536
}
3637

3738
export function deactivate() {

src/treeView/DbContextTreeItem.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { TreeItemCache } from './TreeItemCache';
88
import { ContextValues } from './ContextValues';
99
import type { ProjectFile } from '../types/ProjectFile';
1010
import { getCommandsConfig } from '../config/config';
11+
import type { Logger } from '../util/Logger';
1112

1213
export const dbContextsCache = new TreeItemCache<MigrationTreeItem[]>();
1314

1415
export class DbContextTreeItem extends TreeItem {
1516
private readonly cacheId: string;
1617

1718
constructor(
19+
private readonly logger: Logger,
1820
public readonly label: string,
1921
private readonly projectFile: ProjectFile,
2022
public readonly project: string,
@@ -72,9 +74,9 @@ export class DbContextTreeItem extends TreeItem {
7274
dbContextsCache.set(this.cacheId, children);
7375
return children;
7476
} catch (e) {
75-
await vscode.window.showErrorMessage(
76-
`Unable to get migrations: ${(e as Error).message}`,
77-
);
77+
const msg = `Unable to get migrations: ${(e as Error).message}`.trim();
78+
this.logger.error(msg);
79+
await vscode.window.showErrorMessage(msg, 'OK');
7880
return [];
7981
}
8082
}

src/treeView/ProjectTreeItem.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import { CLI } from '../cli/CLI';
99
import { TreeItemCache } from './TreeItemCache';
1010
import type { ProjectFile } from '../types/ProjectFile';
1111
import { getCommandsConfig } from '../config/config';
12+
import type { Logger } from '../util/Logger';
1213

1314
export const projectsCache = new TreeItemCache<DbContextTreeItem[]>();
1415

1516
export class ProjectTreeItem extends TreeItem {
1617
private readonly cacheId: string;
1718
constructor(
19+
private readonly logger: Logger,
1820
public readonly label: string,
1921
private readonly projectFile: ProjectFile,
2022
private readonly cli: CLI,
@@ -59,6 +61,7 @@ export class ProjectTreeItem extends TreeItem {
5961
const children = dbContexts.map(
6062
dbContext =>
6163
new DbContextTreeItem(
64+
this.logger,
6265
dbContext.name,
6366
this.projectFile,
6467
project,
@@ -69,9 +72,9 @@ export class ProjectTreeItem extends TreeItem {
6972
projectsCache.set(this.cacheId, children);
7073
return children;
7174
} catch (e) {
72-
await vscode.window.showErrorMessage(
73-
`Unable to get dbContexts: ${(e as Error).message}`,
74-
);
75+
const msg = `Unable to get dbContexts: ${(e as Error).message}`.trim();
76+
this.logger.error(msg);
77+
await vscode.window.showErrorMessage(msg, 'OK');
7578
return [];
7679
}
7780
}

src/treeView/TreeDataProvider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { CLI } from '../cli/CLI';
88
import { MigrationTreeItem } from './MigrationTreeItem';
99
import { CommandProvider } from '../commands/CommandProvider';
1010
import { OpenMigrationFileCommand } from '../commands/OpenMigrationFileCommand';
11+
import type { Logger } from '../util/Logger';
1112

1213
export class TreeDataProvider
1314
extends Disposable
@@ -22,6 +23,7 @@ export class TreeDataProvider
2223
> = this._onDidChangeTreeData.event;
2324

2425
constructor(
26+
private readonly logger: Logger,
2527
private readonly projectFiles: ProjectFile[],
2628
private readonly cli: CLI,
2729
) {
@@ -61,7 +63,12 @@ export class TreeDataProvider
6163
} else {
6264
return this.projectFiles.map(
6365
projectFile =>
64-
new ProjectTreeItem(projectFile.name, projectFile, this.cli),
66+
new ProjectTreeItem(
67+
this.logger,
68+
projectFile.name,
69+
projectFile,
70+
this.cli,
71+
),
6572
);
6673
}
6774
}

src/util/Logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class Logger {
1616
}
1717

1818
public format(message: string, type: LogType): string {
19-
return `[${type}] ${message}`;
19+
return `${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()} [${type}] ${message}`;
2020
}
2121

2222
public info(...messages: string[]): void {

0 commit comments

Comments
 (0)