-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
376 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8.1.3 | ||
8.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,98 @@ | ||
{ | ||
"name": "@hapiness/logger", | ||
"version": "1.0.0-rc.6.1", | ||
"description": "Hapiness module for logging", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"private": false, | ||
"scripts": { | ||
"test": "make test", | ||
"pretest": "make pretest", | ||
"coveralls": "make coveralls", | ||
"packaging": "make packaging", | ||
"prebuild": "make pretest && make test && make clean", | ||
"build": "make tsc", | ||
"postbuild": "make packaging" | ||
"name": "@hapiness/logger", | ||
"version": "1.0.0-rc.6.1", | ||
"description": "Hapiness module for logging", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"private": false, | ||
"scripts": { | ||
"test": "make test", | ||
"pretest": "make pretest", | ||
"coveralls": "make coveralls", | ||
"packaging": "make packaging", | ||
"prebuild": "make pretest && make test && make clean", | ||
"build": "make tsc", | ||
"postbuild": "make packaging" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/hapinessjs/logger-module.git" | ||
}, | ||
"keywords": [ | ||
"Logger", | ||
"Log", | ||
"Hapiness", | ||
"Framework", | ||
"NodeJS", | ||
"Node", | ||
"Logger", | ||
"Log", | ||
"Async", | ||
"Decorator", | ||
"RxJS", | ||
"Rx", | ||
"ReactiveX", | ||
"Observable", | ||
"Observer", | ||
"Module", | ||
"ES2015", | ||
"ES2016", | ||
"ES2017", | ||
"ES6", | ||
"ES7", | ||
"ES8", | ||
"Typescript" | ||
], | ||
"contributors": [ | ||
{ | ||
"name": "Julien Fauville", | ||
"url": "https://github.com/Juneil" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/hapinessjs/logger-module.git" | ||
{ | ||
"name": "Antoine Gomez", | ||
"url": "https://github.com/antoinegomez" | ||
}, | ||
"keywords": [ | ||
"Logger", | ||
"Log", | ||
"Hapiness", | ||
"Framework", | ||
"NodeJS", | ||
"Node", | ||
"Logger", | ||
"Log", | ||
"Async", | ||
"Decorator", | ||
"RxJS", | ||
"Rx", | ||
"ReactiveX", | ||
"Observable", | ||
"Observer", | ||
"Module", | ||
"ES2015", | ||
"ES2016", | ||
"ES2017", | ||
"ES6", | ||
"ES7", | ||
"ES8", | ||
"Typescript" | ||
], | ||
"contributors": [ | ||
{ | ||
"name": "Julien Fauville", | ||
"url": "https://github.com/Juneil" | ||
}, | ||
{ | ||
"name": "Antoine Gomez", | ||
"url": "https://github.com/antoinegomez" | ||
}, | ||
{ | ||
"name": "Sébastien Ritz", | ||
"url": "https://github.com/reptilbud" | ||
}, | ||
{ | ||
"name": "Nicolas Jessel", | ||
"url": "https://github.com/njl07" | ||
} | ||
], | ||
"license": "SEE LICENSE IN https://github.com/hapinessjs/logger-module/blob/master/LICENSE.md", | ||
"bugs": { | ||
"url": "https://github.com/hapinessjs/logger-module/issues" | ||
{ | ||
"name": "Sébastien Ritz", | ||
"url": "https://github.com/reptilbud" | ||
}, | ||
"homepage": "https://github.com/hapinessjs/logger-module#readme", | ||
"dependencies": { | ||
"@types/node": "^8.0.13", | ||
"debug": "^2.6.8" | ||
}, | ||
"devDependencies": { | ||
"@hapiness/core": "^1.0.0-rc.6", | ||
"@types/fs-extra": "^3.0.3", | ||
"coveralls": "^2.13.1", | ||
"fs-extra": "^4.0.0", | ||
"intercept-stdout": "^0.1.2", | ||
"istanbul": "^1.1.0-alpha.1", | ||
"mocha": "^3.4.2", | ||
"mocha-typescript": "^1.1.7", | ||
"rimraf": "^2.6.1", | ||
"rxjs": "^5.4.2", | ||
"ts-node": "^3.2.0", | ||
"tslint": "^5.5.0", | ||
"typescript": "^2.4.1", | ||
"unit.js": "^2.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=7.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@hapiness/core": "^1.0.0-rc.6", | ||
"rxjs": "^5.4.2" | ||
{ | ||
"name": "Nicolas Jessel", | ||
"url": "https://github.com/njl07" | ||
} | ||
], | ||
"license": "SEE LICENSE IN https://github.com/hapinessjs/logger-module/blob/master/LICENSE.md", | ||
"bugs": { | ||
"url": "https://github.com/hapinessjs/logger-module/issues" | ||
}, | ||
"homepage": "https://github.com/hapinessjs/logger-module#readme", | ||
"dependencies": { | ||
"@types/chalk": "^0.4.31", | ||
"@types/node": "^8.0.17", | ||
"chalk": "^2.0.1", | ||
"debug": "^2.6.8" | ||
}, | ||
"devDependencies": { | ||
"@hapiness/core": "^1.0.0-rc.6", | ||
"@types/fs-extra": "^4.0.0", | ||
"coveralls": "^2.13.1", | ||
"fs-extra": "^4.0.0", | ||
"intercept-stdout": "^0.1.2", | ||
"istanbul": "^1.1.0-alpha.1", | ||
"mocha": "^3.4.2", | ||
"mocha-typescript": "^1.1.7", | ||
"rimraf": "^2.6.1", | ||
"rxjs": "^5.4.2", | ||
"ts-node": "^3.3.0", | ||
"tslint": "^5.5.0", | ||
"typescript": "^2.4.2", | ||
"unit.js": "^2.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=7.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@hapiness/core": "^1.0.0-rc.6", | ||
"rxjs": "^5.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { InjectionToken } from '@hapiness/core'; | ||
|
||
export const LOGGER_CONFIG = new InjectionToken('logger_config'); | ||
|
||
export interface LoggerConfig { | ||
accessLogs: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { | ||
Optional, | ||
Inject, | ||
Lifecycle, | ||
OnEvent, | ||
Request, | ||
ReplyWithContinue | ||
} from '@hapiness/core'; | ||
import { LoggerService } from './logger.service'; | ||
import { LOGGER_CONFIG, LoggerConfig } from './logger.config'; | ||
import * as Chalk from 'chalk'; | ||
|
||
@Lifecycle({ | ||
event: 'onPreResponse' | ||
}) | ||
export class AccessLogs implements OnEvent { | ||
|
||
constructor( | ||
@Optional() @Inject(LOGGER_CONFIG) private config: LoggerConfig, | ||
private logger: LoggerService | ||
) { | ||
this.config = this.config || { accessLogs: true }; | ||
} | ||
|
||
onEvent(request: Request, reply: ReplyWithContinue) { | ||
if (!this.config.accessLogs) { | ||
reply.continue(); | ||
return; | ||
} | ||
const res = request.raw.res; | ||
const data = { | ||
method: request.method, | ||
path: request.path, | ||
query: request.query, | ||
params: request.params, | ||
statusCode: res.statusCode | ||
}; | ||
this.logger.info( | ||
`${this.getMethod(request.method)} ${request.path} ${this.getStatus(res.statusCode)}`, | ||
data | ||
); | ||
reply.continue(); | ||
} | ||
|
||
/** | ||
* Get formatted status | ||
* | ||
* @param {number} status | ||
*/ | ||
private getStatus(status: number): string { | ||
/* istanbul ignore if */ | ||
if (status >= 400) { | ||
return Chalk.red(status.toString()); | ||
} else { | ||
return Chalk.green(status.toString()); | ||
} | ||
} | ||
|
||
/** | ||
* Get formatted method | ||
* | ||
* @param {string} method | ||
*/ | ||
private getMethod(method: string): string { | ||
const _method = method.toUpperCase(); | ||
/* istanbul ignore next */ | ||
switch (_method) { | ||
case 'GET': | ||
return Chalk.green.bold(_method); | ||
case 'POST': | ||
return Chalk.yellow.bold(_method); | ||
case 'PUT': | ||
return Chalk.blue.bold(_method); | ||
case 'DELETE': | ||
return Chalk.red.bold(_method); | ||
default: | ||
return Chalk.cyan.bold(_method); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
import { HapinessModule } from '@hapiness/core'; | ||
import { HapinessModule, CoreModuleWithProviders } from '@hapiness/core'; | ||
import { LoggerService } from './logger.service'; | ||
import { AccessLogs } from './logger.lifecycle'; | ||
import { LOGGER_CONFIG, LoggerConfig } from './logger.config'; | ||
|
||
@HapinessModule({ | ||
version: '1.0.0-rc.6', | ||
version: '1.0.0-rc.7', | ||
declarations: [ AccessLogs ], | ||
providers: [ LoggerService ], | ||
exports: [ LoggerService ] | ||
}) | ||
export class LoggerModule {} | ||
export class LoggerModule { | ||
static setConfig(config: LoggerConfig): CoreModuleWithProviders { | ||
return { | ||
module: LoggerModule, | ||
providers: [{ provide: LOGGER_CONFIG, useValue: config }] | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.