Skip to content

Commit d516c2d

Browse files
Kasun KodagodaKasun Kodagoda
authored andcommitted
Added a Logger implementation to isolate the Task logging and console logging.
1 parent 49754a8 commit d516c2d

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

BuildTask/ssl-labs-test/Logger.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as Task from 'vsts-task-lib';
2+
import { injectable } from 'inversify';
3+
4+
import { ILogger } from './interfaces/ILogger';
5+
6+
@injectable()
7+
export class Logger implements ILogger {
8+
logDebug(message: string): void {
9+
Task.debug(message);
10+
}
11+
12+
logConsole(message: string): void {
13+
console.log(message);
14+
}
15+
16+
logWarning(message: string): void {
17+
Task.warning(message);
18+
}
19+
20+
logError(message: string): void {
21+
Task.error(message);
22+
}
23+
}

BuildTask/ssl-labs-test/di/inversify.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ import 'reflect-metadata';
33

44
import { ISslLabsService } from '../interfaces/ISslLabsService';
55
import { ITaskInput } from './../interfaces/ITaskInput';
6+
import { ILogger } from '../interfaces/ILogger';
67

78
import TYPES from './types';
89

910
import { SslLabsService } from '../SslLabsService';
1011
import { TaskInput } from './../TaskInput';
12+
import { Logger } from '../Logger';
1113

1214

1315
const container = new Container();
1416

1517
container.bind<ISslLabsService>(TYPES.ISslLabsService).to(SslLabsService).inSingletonScope();
1618
container.bind<ITaskInput>(TYPES.ITaskInput).to(TaskInput).inSingletonScope();
19+
container.bind<ILogger>(TYPES.ILogger).to(Logger).inSingletonScope();
1720

1821
export default container;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const TYPES = {
22
ITaskInput: Symbol('ITaskInput'),
3-
ISslLabsService: Symbol('ISslLabsService')
3+
ISslLabsService: Symbol('ISslLabsService'),
4+
ILogger: Symbol('ILogger')
45
};
56

67
export default TYPES;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface ILogger {
2+
logDebug(message: string): void;
3+
logConsole(message: string): void;
4+
logWarning(message: string): void;
5+
logError(message: string): void;
6+
}

0 commit comments

Comments
 (0)