Skip to content

Commit

Permalink
feat(logger): initial commit for logger
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlautier committed May 16, 2016
1 parent 0e83681 commit 1904d06
Show file tree
Hide file tree
Showing 20 changed files with 2,497 additions and 446 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
"yargs": "^4.6.0"
},
"dependencies": {},
"peerDependencies": {
"@angular/core": "^2.0.0-rc.1",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12"
},
"jspm": {
"registry": "jspm",
"main": "amd/index",
Expand All @@ -66,4 +71,4 @@
"devDependencies": {}
},
"typings": "dist/typings/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion src/logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Usage

```javascript
import {LogService, ILog} from "core/common";
import {LogService, ILog} from "ssv-ng2-core";

const id = "auth.service";

Expand Down
18 changes: 18 additions & 0 deletions src/logging/logger.factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Injectable} from "@angular/core";

import {ILog} from "./logger.model";
import {Log, LoggerService} from "./logger.service";

@Injectable()
export class LoggerFactory {

constructor(
private loggerService: LoggerService
) {

}

getInstance(sourceId: string): ILog {
return new Log(sourceId, this.loggerService);
}
}
6 changes: 6 additions & 0 deletions src/logging/logger.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface ILog {
debug(method: string, message?: string, data?: any): void;
info(method: string, message?: string, data?: any): void;
warn(method: string, message?: string, data?: any): void;
error(method: string, message?: string, data?: any): void;
}
36 changes: 17 additions & 19 deletions src/logging/logger.srv.ts → src/logging/logger.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import {getLogger} from "aurelia-logging";
import {Injectable} from "@angular/core";

import {ILog} from "./logger.model";

export class LogService {
@Injectable()
export class LoggerService {

getLogger(sourceId: string): ILog {
let logger = getLogger(sourceId);
return new Log(logger);
log(logType: string, message: string, data?: any): void {
if (data) {
(<any>console)[logType](message, data);
} else {
(<any>console)[logType](message);
}
}
}

export class Log implements ILog {

constructor(private logger: any) {
constructor(
private sourceId: string,
private logger: LoggerService
) {
}

debug(method: string, message?: string, data?: any): void {
Expand All @@ -31,25 +39,15 @@ export class Log implements ILog {
}

private log(type: string, method: string, message?: string, data?: any) {
if (data) {
this.logger[type](`${this.buildLogMessage(method, message)}`, data);
} else {
this.logger[type](`${this.buildLogMessage(method, message)}`);
}
this.logger.log(type, `${this.buildLogMessage(method, message)}`, data);
}

private buildLogMessage(method: string, message?: string): string {
if (message) {
return `${method} :: ${message}`;
return `[${this.sourceId}::${method}] ${message}`;
} else {
return `${method}`;
return `[${this.sourceId}::${method}]`;
}
}
}

export interface ILog {
debug(method: string, message?: string, data?: any): void;
info(method: string, message?: string, data?: any): void;
warn(method: string, message?: string, data?: any): void;
error(method: string, message?: string, data?: any): void;
}
17 changes: 0 additions & 17 deletions src/logging/logger.srv.spec.ts

This file was deleted.

12 changes: 11 additions & 1 deletion src/logging/logging.ts
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
export * from "./logger.srv";
import {LoggerFactory} from "./logger.factory";
import {LoggerService} from "./logger.service";

export * from "./logger.service";
export * from "./logger.factory";
export * from "./logger.model";

export const LOGGER_PROVIDERS: any = [
LoggerFactory,
LoggerService
];
Loading

0 comments on commit 1904d06

Please sign in to comment.